Hi - I am new SuiteCRM OnDemand user. I have used aPaas platforms for years and am glad to be exploring SuiteCRM.
In my previous aPaas platform, LongJump (aka AgileApps), it is possible to make a form field read only.
In SuiteCRM, I have a situation where I have a calculated field (Workflow) on the Account EditView (linked to DetailView). I would like the field in EditView to not be editable since a user may be confused that they CAN edit the calculated field text but when they save, they will find that their change was not saved.
Since I have DetailView linked to EditView, I cant simply not list the calculated field on the EditView.
Strangely enough, I have the need to do the exact same thing! I found this article about how to do it, but haven’t tried yet. If you get to it before me, I’d love to hear how you made out!
I have created new custom field under aos_products module, but I don’t know how to set it read-only field. The user should not be allowed to update value.
You can make it so users can’t edit certain fields by going to : /custom/modules//metadata/editviewdefs.php In this file, add ‘type’⇒’readonly’, to the definitions of the file you want to make readonly.
Afterwards, run a Quick Repair & Rebuild and clear your Browser’s cache to view changes.
you have to turn off inline edit or they’ll be able to edit inline
The above doesn’t format checkbox fields and the like. It only works for text fields. If you have a field like checkboxes or radio that require formatting, you can do this as follows:
@rsp, sorry just re-read, the code above will make it read only for everyone. For just admin you have to jump through some hoops. It’s different depending on the type of field you have to use customCode to format the output if the user is not admin. It’s slightly differnent for each type of field. What type of field do you want to make read only except admins?
Here is an example of a text field, this will not work for dropdowns or checkboxes.
First:
copy modules/Contacts/views/view.edit.php to custom/modules/Contacts/views/view.edit.php
You’re going to need to pass two variables to the Smart Template: 1) isAdministrator 2) readOnly
class AccountsViewEdit extends ViewEdit
{
public function __construct()
{
parent::__construct();
$this->useForSubpanel = true;
$this->useModuleQuickCreateTemplate = true;
}
public function display()
{
global $current_user;
// Check if the user is an administrator
$isAdministrator = $current_user->is_admin;
// Set the $readOnly variable based on the user's administrator status
$readOnly = $isAdministrator ? '' : 'readonly = "readonly"';
// Assign $readOnly to Smarty template
$this->ev->ss->assign('readOnly', $readOnly);
//Assign $isAdministrator to Smarty template
$this->ev->ss->assign('isAdministrator', $isAdministrator);
parent::display(); // Call the parent display function to render the view
}