Create a readonly field

Hi,

I am populating a table/module using a trigger from Workflow module.

Later I need to modify part of the new records but I need to protect a couple of fields there.

I used:

http://developer.sugarcrm.com/2012/11/08/using-sugar-logic-to-conditonal-make-fields-read-only/

I guess that is not supported on SuiteCRM due to it is not reflecting the new code after the “Quick Repair and Rebuild” action.

Kindly, can you suggest a way to do that?

My current code is:

[root@suitcrm Dependencies]# pwd
/var/www/html/SuiteCRM-7.3-MAX/custom/Extension/modules/OT1_OT_Confirmacion/Ext/Dependencies
[root@suitcrm Dependencies]#

[root@suitcrm Dependencies]# cat ot_numero_readonly.php

<?php $dependencies['OT_Confirmacion']['ot_numero'] = array( 'hooks' => array("edit"), 'trigger' => 'true', //Optional, the trigger for the dependency. Defaults to 'true'. 'triggerFields' => array('status'), 'onload' => true, //Actions is a list of actions to fire when the trigger is true 'actions' => array( array( 'name' => 'ReadOnly', //The parameters passed in will depend on the action type set in 'name' 'params' => array( 'target' => 'ot_numero', 'value' => 'true', ), ), ), ); [root@suitcrm Dependencies]# Thanks in advance

Hi,

You can make it so users cannot edit records by using SecuritySuite, but if you want to make it so they cannot edit specific fields:

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.

i.e:

array (
            'name' => 'testdropdown_c',
              'studio' => 'visible',
            'label' => 'LBL_TESTDROPDOWN',
          ),

Would become:

array (
            'name' => 'testdropdown_c',
              'type'=>'readonly',
              'studio' => 'visible',
            'label' => 'LBL_TESTDROPDOWN',
          ),

Afterwards, run a Quick Repair & Rebuild and clear your Browser’s cache to view changes.

1 Like

Hi John, your instructions work.
There is the problem that all users can not change the field.
Is there a way to allow the change field only at the administrator only?
Thanks

Hi,

The guide: https://suitecrm.com/suitecrm/blog/entry/make-an-edit-view-field-read-only-based-on-user-role-in-suitecrm-or-sugarcrm-ce

Shows you how to make fields read only depending on a user’s role.
I’d imagine that you could re-purpose this in conjunction with Security Suite’s role functionality to make it so that the field is read-only for all User roles, Except Administrator.