SugarCRM SupportDocumentationSugar DeveloperSugar Developer Guide 7.9ArchitectureSugar LogicDependency ActionsReadOnly

ReadOnly

Overview

The SugarLogic  ReadOnly action, located in ./include/Expressions/Actions/ReadOnlyAction.php, is used to determine if a field is editable or not based on a formula.

Implementation

While the dependency metadata for your module can be defined in ./modules/<module>/metadata/dependencydefs.php and  ./custom/modules/<module>/metadata/dependencydef.php, it is recommended to use the extension framework when customizing stock modules to prevent third party plugins from conflicting with your customizations. The following section will demonstrate how to implement a read-only dependency.

ReadOnly Parameters

Parameter Type Description
target String The name of the field to make read only.
value String

This parameter can accept a boolean formula or true and false values.  Normally you would put a
SugarLogic formula here to set the boolean.

For more information on the various parameters in the dependency definitions, please refer to the dependency actions documentation.

Example

For our example, we will create a dependency on the Accounts module that makes the name field read-only when the lock_record_c field has been checked. The first step is to create the  lock_record_c checkbox field in Studio and add it to your Record View layout. When this checkbox is checked, we will make the name field read-only. Our example extension definition is shown below: 

./custom/Extension/modules/<module>/Ext/Dependencies/custom_name_read_only.php

<?php

    $dependencies['Accounts']['readonly_fields'] = array(
        'hooks' => array("edit"),
        'trigger' => 'true',
        //Optional, the trigger for the dependency. Defaults to 'true'.
        'triggerFields' => array('lock_record_c'),
        'onload' => true,
        //Actions is a list of actions to fire when the trigger is true
        // You could list multiple fields here each in their own array under 'actions'
        'actions' => array(
            array(
                'name' => 'ReadOnly',
                //The parameters passed in will depend on the action type set in 'name'
                'params' => array(
                    'target' => 'name',
                    'value' => 'equal($lock_record_c,true)',
                ),
            ),
        ),
    );

Once you have all the files in place you will need to navigate to Admin > Repairs > and run a Quick Repair and Rebuild.

Note: It is important that the module name is plural ('Accounts' vs. 'Account') and that the name of the dependency, "readonly_fields" in this example, is unique.

Considerations

  1. In some scenarios, you may want a specific field to always be read-only. To accomplish this, you can modify the 'value' attribute to always be "true". Given the above example, you would modify:

    'value' => 'equal($lock_record_c,true)',  

    to be:

    'value' => 'true',   

Last modified: 04/25/2018 11:25pm