SetRequired
Overview
The SugarLogic SetRequired
action, located in ./include/Expressions/Actions/SetRequiredAction.php
, is used to determine if a field is required.
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.
SetRequired Parameters
Parameter | Type | Description |
target | String | The name of the field to make required. |
label | String | id of label element for this field |
value | String | Formula used to determine if the field should be required. |
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 Cases module that will mark the resolution
field as required when the status
field is set to "Closed". Our example extension definition is shown below:
./custom/Extension/modules/<module>/Ext/Dependencies/required_resolution_dep.php
<?php
$dependencies['Cases']['required_resolution_dep'] = array(
'hooks' => array("edit"),
'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',
'label' => 'resolution_label',
'value' => 'equal($status, "Closed")',
),
),
),
);
Once you have the file 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 ('Cases' vs. 'Case') and that the name of the dependency, "required_resolution_dep" in this example, is unique.