SugarCRM SupportProduct GuidesSugar DeveloperSugar Developer Guide 11.0ArchitectureSugar LogicUsing Sugar Logic DirectlyCreating a Custom Dependency Using Metadata

Creating a Custom Dependency Using Metadata

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

Dependencies can have the following properties:

  • hooks : Defines when the dependency should be evaluated. Possible values are edit (on edit/quickCreate views), view (Detail/Wireless views), save (during a save action), and all (any time the record is accessed/saved).
  • trigger : A boolean formula that defines if the actions should be fired. (optional, defaults to 'true')
  • triggerFields : An array of field names that when when modified should trigger re-evaluation of this dependency on edit views. (optional, defaults to the set of fields found in the trigger formula)
  • onload : If true, the dependency will be fired when an edit view loads (optional, defaults to true)
  • actions : An array of action definitions to fire when the trigger formula is true.
  • notActions : An array of action definitions to fire when the trigger formula is false. (optional)

The actions are defined as an array with the name of the action and a set of parameters to pass to that action. Each action takes different parameters, so you will have to check each actions class constructor to check what parameters it expects.

The following example dependency will set the resolution field of cases to be required when the status is Closed:

<?php

$dependencies['Cases']['required_resolution_dep'] = array(
    'hooks' => array("edit"),
    //Optional, the trigger for the dependency. Defaults to 'true'.
    'trigger' => 'true', 
    'triggerFields' => array('status'),
    'onload' => true,
    //Actions is a list of actions to fire when the trigger is true
    'actions' => array(
        array(
            'name' => 'SetRequired',
            //The parameters passed in will depend on the action type set in 'name'
            'params' => array(
                'target' => 'resolution',
                //id of the label to add the required symbol to
                'label' => 'resolution_label',
                //Set required if the status is closed
                'value' => 'equal($status, "Closed")' 
            )
        ),
    ),
    //Actions fire if the trigger is false. Optional.
    'notActions' => array(),
);

 

Last modified: 2021-02-17 02:44:13