How to make certain field readonly or disabled based on some other field’s value using SugarCRM Dependencies

SugarCRM Dependencies

Let’s suppose you want to make Mobile field readonly based on Title field’s value in Contacts Module.

SugarCRM Dependencies:

You can achieve above with SugarCRM Dependencies. Experienced SugarCRM developers already know about Dependencies but if you are not familiar with them, no worries and carry on reading! These are used to add dependent actions to fields and forms that can leverage more complicated logic that is not yet available in Studio.

Properties:

 

Internal Name dependencies
Manifest Installdef dependencies
Extension Directory ./custom/Extension/modules/<module>/Ext/Dependencies/
Extension File ./custom/modules/<module>/Ext/Dependencies/deps.ext.php

More information about dependency actions can be found in the Sugar Logic section.

Adding Dependency to Contacts Module:

As mentioned in properties of Dependencies the dependency files should be located in ./custom/Extension/modules/{module}/Ext/Dependencies/{dependency name}.php and be rebuilt with a quick repair after modification.

As we are going to add a dependency for Contacts Module we will be creating a dependency file at

custom/Extension/modules/Contacts/Ext/Dependencies

Inside the file put below code

$dependencies['Contacts']['phone_mobile_readonly'] =    array(
    'hooks' => array("edit"),
    'trigger' => 'equal($title, "CTO")', //Optional, the trigger for the dependency. Defaults to 'true'.
    'triggerFields' => array('title'),
    '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' => 'phone_mobile',
                'value' => 'true',
            ),
        ),
    ),
);

 

Save the file and do a quick repair and rebuild.

The dependency we just created says that the Mobile Phone Field will be readonly if the Title of the person is CTO. This works perfectly in Sugar 6 and seems to partially work in Sugar 7

 

 

Author: Tahir Yasin

Tahir is a Passionate Web Developer from Lahore, Pakistan and a guy with NEVER-STOP-LEARNING attitude who keeps an eye on emerging technologies and customer trends.

Leave a Reply

Your email address will not be published. Required fields are marked *