id
stringlengths
14
16
text
stringlengths
33
5.27k
source
stringlengths
105
270
5da184731a37-1
Action : A method that modifies the current record or layout in some way Dependency : A complete logical unit that includes a trigger and one or more actions Sugar Formula Engine Formulas The fundamental object is called a formula. A formula can be evaluated for a given record using the Sugar Logic parser. Some example formulas are: Basic addition: add(1, 2) Boolean values: not(equal($billing_state, "CA")) Calculation: multiply(number($employees), $seat_cost, 0.0833) Types Sugar Logic has several fundamental types: number, string, boolean, and enum (lists). Functions may take in any of these types or combinations thereof and return as output one of these types. Fields may also often have their value set to only a certain type. Number Type
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/index.html
5da184731a37-2
Number Type Number types essentially represent any real number (which includes positive, negative, and decimal numbers). They can be plainly typed as input to any function. For example, the operation (10 + 10 + (15 - 5)) can be performed as follows: add(10, 10, subtract(15, 5)) String Type A string type is very much like a string in most programming languages. However, it can only be declared within double quotes. For example, consider this function, which returns the length of the input string: strlen("Hello World") The function would appropriately return the value 11. Boolean Type
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/index.html
5da184731a37-3
The function would appropriately return the value 11. Boolean Type A boolean type is simple. It can be one of two values: "true" or "false". This type mainly acts as a flag that indicates whether a condition has been met or not. For example, this function contains takes two strings as input and returns "true" if the first string contains the second string, or "false" otherwise: and(contains("Hello World", "llo Wo"), true) The function would appropriately return the value "true". Enum Type (list) An enum type is a collection of items. The items do not need to all be of the same type, they can be varied. An enum can be declared using the enum function as follows: enum("hello world!", false, add(10, 15)) Alternatively, the createList() function (an alias to enum) can be used to create enums in a formula.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/index.html
5da184731a37-4
createList("hello world!", false, add(10, 15)) This function would appropriately return an enum type containing "hello world!", false, and 25 as its elements. Link Type (relationship) A link represents one side of a relationship and is used to access related records. For example, the accounts link field of Contacts is used to access the account_type field of the account related to a contact: related($accounts, "account_type") For most of the out-of-the-box relationships, links are named with the name of the related module, in lower case. Follow these steps to find the name of the link fields for relationships that do not follow the convention above: Open the vardef file for the module you are working on: ./cache/modules/{module}/{module}vardefs.php Find the link field that matches the relationship you are looking for. Functions
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/index.html
5da184731a37-5
Find the link field that matches the relationship you are looking for. Functions Functions are methods to be used in formulas. Each function has a function name, a parameter count, a parameter type requirement, and returns a value. Some functions such as add() can take any number of parameters. For example: add(1), add(1, 2), and add(1, 2, 3) are all valid formulas. Functions are designed to produce the same result whether executed on the server or client. Triggers A trigger is an object that listens for changes in field values and, after a change occurs, triggers the associated actions in a dependency. Actions
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/index.html
5da184731a37-6
Actions Actions are functions that modify a target in some way and are fired when the trigger is TRUE. Most Actions require at least two parameters: a target and a formula. For example, a style action will change the style of a field based on a passed-in string formula. A value action will update a value of a field by evaluating a passed in formula. notActions notActions are functions that modify a target in some way and are fired when the trigger is FALSE. notActions are optional and if they are not defined then nothing will fire when the trigger is FALSE.  Most notActions require at least two parameters: a target and a formula. For example, a style action will change the style of a field based on a passed-in string formula. A value action will update a value of a field by evaluating a passed in formula. Dependencies
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/index.html
5da184731a37-7
A Dependency describes a set of rules based on a trigger and a set of actions. Examples include a field whose properties must be updated dynamically or a panel which must be hidden when a drop down value is not selected. When a Dependency is triggered it will appropriately carry out the action it is designed to. A basic Dependency is when a field's value is dependent on the result of evaluating a Expression. For example, consider a page with five fields with It's "a", "b", "c", "d", and "sum". A generic Dependency can be created between "sum" and the other four fields by using an Expression that links them together, in this case an add Expression. So we can define the Expression in this manner: 'add($a, $b, $c, $d)' where each field id is prefixed with a dollar ($) sign so that the value of the field is dynamically replaced at the time of the execution of the Expression.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/index.html
5da184731a37-8
An example of a more customized Dependency is when the field's style must be somehow updated to a certain value. For example, the DIV with id "temp" must be colored blue. In this case we need to change the background-color property of "temp". So we define a StyleAction in this case and pass it the field id and the style change that needs to be performed and when the StyleAction is triggered, it will change the style of the object as we have specified. Sugar Logic Based Features Calculated Fields
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/index.html
5da184731a37-9
Sugar Logic Based Features Calculated Fields Fields with calculated values can now be created from within Studio and Module Builder. The values are calculated based on Sugar Logic formulas. These formulas are used to create a new dependency that are executed on the client side in edit views and the server side on save. The formulas are saved in the varies or vardef extensions and can be created and edited directly. For example, the metadata for a simple calculated commission field in opportunities might look like: 'commission_c' => array( 'name' => 'commission_c', 'type' => 'currency', 'calculated' => true, 'formula' => 'multiply($amount, 0.1)', //enforced causes the field to appear read-only on the layout 'enforced' => true ), Dependent fields
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/index.html
5da184731a37-10
'enforced' => true ), Dependent fields A dependent field will only appear on a layout when the associated formula evaluates to the Boolean value true. Currently these cannot be created through Studio and must be enabled manually with a custom vardef or vardef extension. The "dependency" property contains the expression that defines when this field should be visible. An example field that only appears when an account has an annual revenue greater than one million. 'dep_field'=> array( 'name' => 'dep_field', 'type' => 'varchar', 'dependency' => 'greaterThan($annual_revenue, 1000000)', ), Dependent dropdowns
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/index.html
5da184731a37-11
), Dependent dropdowns Dependent dropdowns are dropdowns for which options change when the selected value in a trigger dropdown changes. The metadata is defined in the vardefs and contains two major components, a "trigger" id which is the name of the trigger dropdown field and a 'visibility grid' that defines the set of options available for each key in the trigger dropdown. For example, you could define a sub-industry field in accounts whose available values depend on the industry field. 'sub_industry_c' => array( 'name' => 'sub_industry_c', 'type' => 'enum', 'options' => 'sub_industry_dom', 'visibility_grid'=> array( 'trigger' => 'industry', 'values' => array( 'Education' => array( 'primary',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/index.html
5da184731a37-12
'Education' => array( 'primary', 'secondary', 'college' ), 'Engineering' => array( 'mechanical', 'electrical', 'software' ), ), ), ), Clearing the Sugar Logic Cache The ./updatecache.php script traverses the Expression directory for every file that ends with "Expression.php" (ignoring a small list of excepted files) and constructs both a PHP and a JavaScript functions cache file which resides in ./cache/Expressions/functions_cache.js and ./cache/Expressions/functionmap.php. If you create your custom expressions, you will need to rebuild the sugar logic functions by navigating to: Admin > Repair > Rebuild Sugar Logic Functions
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/index.html
5da184731a37-13
Admin > Repair > Rebuild Sugar Logic Functions TopicsDependency ActionsThe following sections outline the available SugarLogic dependency actions.Extending Sugar LogicHow to write custom Sugar Logic functions.Using Sugar Logic DirectlyHow to use Sugar Logic Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/index.html
d957f143bc42-0
Using Sugar Logic Directly How to use Sugar Logic
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/index.html
d957f143bc42-1
TopicsAccessing an External API with a Sugar Logic ActionLet us say we were building a new Action called "SetZipCodeAction" that uses the Yahoo geocoding API to get the zip code for a given street + city + state address.Creating a Custom Dependency for a ViewDependencies can also be created and executed outside of the built in features. For example, if you wanted to have the description field of the Calls module become required when the subject contains a specific value, you could extend the calls edit view to include that dependency.Creating a Custom Dependency Using MetadataThe files should be located in ./custom/Extension/modules/{module}/Ext/Dependencies/{dependency name}.php and be rebuilt with a quick repair after modification.Using Dependencies in Logic HooksDependencies can not only be executed on the server side but can be useful entirely on the server. For example, you could have a dependency that sets a rating
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/index.html
d957f143bc42-2
can be useful entirely on the server. For example, you could have a dependency that sets a rating based on a formula defined in a language file.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/index.html
d957f143bc42-3
Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/index.html
c85d47a8e872-0
Using Dependencies in Logic Hooks Overview Dependencies can not only be executed on the server side but can be useful entirely on the server. For example, you could have a dependency that sets a rating based on a formula defined in a language file. <?php require_once "include/Expressions/Dependency.php"; require_once "include/Expressions/Trigger.php"; require_once "include/Expressions/Expression/Parser/Parser.php"; require_once "include/Expressions/Actions/ActionFactory.php"; class Update_Account_Hook { function updateAccount($bean, $event, $args) { $formula = translate('RATING_FORMULA', 'Accounts'); $triggerFields = Parser::getFieldsFromExpression($formula);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Using_dependencies_in_Logic_Hooks/index.html
c85d47a8e872-1
$triggerFields = Parser::getFieldsFromExpression($formula); $dep = new Dependency('updateRating'); $dep->setTrigger(new Trigger('true', $triggerFields)); $dep->addAction(ActionFactory::getNewAction('SetValue', array( 'target' => 'rating', 'value' => $formula ))); $dep->fire($bean); } }   Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Using_dependencies_in_Logic_Hooks/index.html
8241998facff-0
Creating a Custom Dependency for a View Dependencies can also be created and executed outside of the built in features. For example, if you wanted to have the description field of the Calls module become required when the subject contains a specific value, you could extend the calls edit view to include that dependency. ./custom/modules/Calls/views/view.edit.php <?php require_once "include/MVC/View/views/view.edit.php"; require_once "include/Expressions/Dependency.php"; require_once "include/Expressions/Trigger.php"; require_once "include/Expressions/Expression/Parser/Parser.php"; require_once "include/Expressions/Actions/ActionFactory.php"; class CallsViewEdit extends ViewEdit { function CallsViewEdit() { parent::ViewEdit(); }
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Creating_a_Custom_Dependency_for_a_View/index.html
8241998facff-1
function CallsViewEdit() { parent::ViewEdit(); } function display() { parent::display(); $dep = new Dependency("description_required_dep"); $triggerExp = 'contains($name, "important")'; //will be array('name') $triggerFields = Parser::getFieldsFromExpression($triggerExp); $dep->setTrigger(new Trigger($triggerExp, $triggerFields)); //Set the description field to be required if "important" is in the call subject $dep->addAction(ActionFactory::getNewAction('SetRequired', array( 'target' => 'description', 'label' => 'description_label', 'value' => 'true' )));
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Creating_a_Custom_Dependency_for_a_View/index.html
8241998facff-2
'value' => 'true' ))); //Set the description field to NOT be required if "important" is NOT in the call subject $dep->addFalseAction(ActionFactory::getNewAction('SetRequired', array( 'target' => 'description', 'label' => 'description_label', 'value' => 'false' ))); //Evaluate the trigger immediatly when the page loads $dep->setFireOnLoad(true); $javascript = $dep->getJavascript(); echo SUGAR.forms.AssignmentHandler.registerView('EditView'); {$javascript} EOQ; } } ?>
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Creating_a_Custom_Dependency_for_a_View/index.html
8241998facff-3
{$javascript} EOQ; } } ?> The above code creates a new Dependency object with a trigger based on the 'name' (Subject) field in of the Calls module. It then adds two actions. The first will set the description field to be required when the trigger formula evaluates to true (when the subject contains "important"). The second will fire when the trigger is false and removes the required property on the description field. Finally, the javascript version of the Dependency is generated and echoed onto the page. Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Creating_a_Custom_Dependency_for_a_View/index.html
1efe023483fd-0
Accessing an External API with a Sugar Logic Action Let us say we were building a new Action called "SetZipCodeAction" that uses the Yahoo geocoding API to get the zip code for a given street + city + state address. Since the Yahoo geocoding API requires JSON requests and returns XML data, we will have to write both PHP and JavaScript code to make and interpret the requests. Because accessing external APIs in a browser is considered cross-site scripting, a local proxy will have to be used. We will also allow the street, city, state parameters to be passed in as formulas so the action could be used in more complex Dependencies.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Accessing_an_External_API_with_a_Sugar_Logic_Action/index.html
1efe023483fd-1
First, we should add a new action that acts as the proxy for retrieving data from the Yahoo API. The easiest place to add that would be a custom action in the "Home" module. The file that will act as the proxy will be .custom/modules/Home/geocode.php. It will take in the parameters via a REST call, make the call to the Yahoo API, and return the result in JSON format. geocode.php contents: <?php function getZipCode($street, $city, $state) { $appID = "6ruuUKjV34Fydi4TE.ca.I02rWh.9LTMPqQnSQo4QsCnjF5wIvyYRSXPIzqlDbI.jfE-"; $street = urlencode($street); $city = urlencode($city);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Accessing_an_External_API_with_a_Sugar_Logic_Action/index.html
1efe023483fd-2
$city = urlencode($city); $state = urlencode($state); $base_url = "http://local.yahooapis.com/MapsService/V1/geocode?"; $params = "appid={$appID}&street={$street}&city={$city}&state={$state}"; //use file_get_contents to easily make the request $response = file_get_contents($base_url . $params); //The PHP XML parser is going to be overkill in this case, so just pull the zipcode with a regex. preg_match('/\([\d-]*)\/', $response, $matches); return $matches[1]; } if (!empty($_REQUEST['execute'])) {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Accessing_an_External_API_with_a_Sugar_Logic_Action/index.html
1efe023483fd-3
} if (!empty($_REQUEST['execute'])) { if (empty($_REQUEST['street']) || empty($_REQUEST['city']) || empty($_REQUEST['state'])) { echo("Bad Request"); } else { echo json_encode(array('zip' => getZipCode($_REQUEST['street'], $_REQUEST['city'], $_REQUEST['state']))); } } ?> Next, we will need to map the geocode action to the geocode.php file. This is done by adding an action map to the Home Module. Create the file ./custom/modules/Home/action_file_map.php and add the following line of code: <?php
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Accessing_an_External_API_with_a_Sugar_Logic_Action/index.html
1efe023483fd-4
<?php $action_file_map['geocode'] = 'custom/modules/Home/geocode.php'; We are now ready to write our Action. Start by creating the file ./custom/include/Expressions/Actions/SetZipCodeAction.php. This file will use the proxy function directly from the PHP side and make an asynchronous call on the javascript side to the proxy. SetZipCodeAction.php contents: <?php require_once "include/Expressions/Actions/AbstractAction.php"; class SetZipCodeAction extends AbstractAction { protected $target = ""; protected $streetExp = ""; protected $cityExp = ""; protected $stateExp = ""; function SetZipCodeAction($params) { $this->target = empty($params['target']) ? " " : $params['target'];
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Accessing_an_External_API_with_a_Sugar_Logic_Action/index.html
1efe023483fd-5
$this->streetExp = empty($params['street']) ? " " : $params['street']; $this->cityExp = empty($params['city']) ? " " : $params['city']; $this->stateExp = empty($params['state']) ? " " : $params['state']; } static function getJavascriptClass() { return "'($this->target}', '{$this->streetExp}', '{$this->cityExp}', '{$this->stateExp}')"; } function fire(&$bean) { require_once("custom/modules/Home/geocode.php"); $vars = array( 'street' => 'streetExp', 'city' => 'cityExp', 'state' => 'stateExp'
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Accessing_an_External_API_with_a_Sugar_Logic_Action/index.html
1efe023483fd-6
'city' => 'cityExp', 'state' => 'stateExp' ); foreach($vars as $var => $exp) { $toEval = Parser::replaceVariables($this->$exp, $bean); $var = Parser::evaluate($toEval)->evaluate(); } $target = $this->target; $bean->$target = getZipCode($street, $city, $state); } function getDefinition() { return array( "action" => $this->getActionName(), "target" => $this->target, ); } static function getActionName() { return "SetZipCode"; } } ?>
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Accessing_an_External_API_with_a_Sugar_Logic_Action/index.html
1efe023483fd-7
{ return "SetZipCode"; } } ?> Once you have the action written, you need to call it somewhere in the code. Currently, this must be done as shown above using custom views, logic hooks, or custom modules. Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Accessing_an_External_API_with_a_Sugar_Logic_Action/index.html
d703d558e3aa-0
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)
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Creating_a_custom_dependency_using_metadata/index.html
d703d558e3aa-1
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',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Creating_a_custom_dependency_using_metadata/index.html
d703d558e3aa-2
'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(), ); Â
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Creating_a_custom_dependency_using_metadata/index.html
d703d558e3aa-3
'notActions' => array(), );   Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Using_Sugar_Logic_Directly/Creating_a_custom_dependency_using_metadata/index.html
fe5a572430ed-0
Dependency Actions Overview The following sections outline the available SugarLogic dependency actions. Dependency Parameters Dependency definitions will generally contain most, if not all, of the parameters displayed in the table below. The following sections will outline each dependency action as well as dependency specific parameters. Parameter Type Description hooks  Array  The views to execute the trigger on. Possible values are: "edit", "view", "save" and "all".   If you include 'save' or 'all' then SugarCRM will try to save the calculated value to the database.  So if your dependency is display only then only include the views that it will show up on. trigger  String  Optional. The trigger for the dependency. Defaults to 'true'. triggerFields  Array
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/index.html
fe5a572430ed-1
triggerFields  Array  The list of fields to watch for change events. When changed, the trigger expressions will be recalculated. onload  Boolean  Whether or not to trigger the dependencies when the page is loaded. actions  Array  The list of dependencies to execute when the trigger expression is true. notActions  Array  The list of dependencies to execute when the trigger expression is false. Â
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/index.html
fe5a572430ed-2
TopicsReadOnlyThe 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.SetOptionsThe SugarLogic SetOptions action, located in ./include/Expressions/Actions/SetOptionsAction.php, is used to set the options list of a dropdown field based on a formula.SetPanelVisibilityThe SugarLogic SetPanelVisibility action, defined in ./include/Expressions/Actions/PanelVisibilityAction.php, is used to determine the visibility of a record view panel based on a formula.SetRequiredThe SugarLogic SetRequired action, located in ./include/Expressions/Actions/SetRequiredAction.php, is used to determine if a field is required.SetValueThe SugarLogic SetValue action, located in
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/index.html
fe5a572430ed-3
to determine if a field is required.SetValueThe SugarLogic SetValue action, located in ./include/Expressions/Actions/SetValueAction.php, is used to set the value of a field based on a formula.SetVisibilityThe SugarLogic SetVisibility action, located in ./include/Expressions/Actions/VisibilityAction.php , is used to determine the visibility logic of a field based on a formula.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/index.html
fe5a572430ed-4
Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/index.html
980e6d78d8ef-0
SetOptions Overview The SugarLogic SetOptions action, located in ./include/Expressions/Actions/SetOptionsAction.php, is used to set the options list of a dropdown field 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. Setoptions Parameters Parameter Type Description target String The name of the dropdown field that you want to change the option list for keys String
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetOptions/index.html
980e6d78d8ef-1
keys String A formula used to get the option list keys for the target field or a list name from which keys will be extracted. labels String A formula used to get the option list labels for the target field or a list name from which labels will be extracted. For more information on the various parameters in the dependency definitions, please refer to the dependency actions documentation. Examples The following sections outline the various ways this dependency can be implemented. Using an Existing DropDown List You can also set the options list to any current options list already in the system  For example if you wanted to have the industry dropdown in Accounts show the 'bug_type_dom' list from Bugs you could do this <?php $dependencies['Leads']['setoptions_industry'] = array( 'hooks' => array("edit","save"), 'trigger' => 'true',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetOptions/index.html
980e6d78d8ef-2
'trigger' => 'true', 'triggerFields' => array('industry'), 'onload' => true, 'actions' => array( array( 'name' => 'SetOptions', 'params' => array( 'target' => 'industry', 'keys' => 'getDropdownKeySet("bug_type_dom")', 'labels' => 'getDropdownValueSet("bug_type_dom")' ), ), ), ); This would grab the keys and label from the 'bug_type_dom' using the getDropdownKeySet() and getDropdownValueSet() JavaScript functions and display them instead of the normal list.Â
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetOptions/index.html
980e6d78d8ef-3
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 ('Accounts' vs. 'Account') and that the name of the dependency, "setoptions_industry" in this example, is unique. Complex Dynamic Lists For our first example, we will change a dropdown called fruits_c to include only fruits that are in season.  This could be done with a dependent dropdown but that would require the user to pick the proper season.  With this, we can have a function that returns only fruit that is in season right now.  I added the dropdown fruits_c to Leads and created a new list for it that looks like this $app_list_strings['fruits_list']=array (
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetOptions/index.html
980e6d78d8ef-4
$app_list_strings['fruits_list']=array ( 'Apples' => 'Apples', 'Strawberries' => 'Strawberries', 'Mangos' => 'Mangos', 'Pineapples' => 'Pineapples', 'Blackberries' => 'BlackBerries', 'BlueBerries' => 'BlueBerries', ); To keep it simple I made the labels and the keys the same. Then I extended SugarLogic as outlined in Extending SugarLogic and made a new function called fruitInSeason() that returns a string reflecting what fruit is in season right now.  To work for the createList() function it would return a list like "Apples","Mangos","BlueBerries".
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetOptions/index.html
980e6d78d8ef-5
./custom/Extension/modules/<module>/Ext/Dependencies/custom_fruit_in_season.php <?php $dependencies['Leads']['setoptions_fruit'] = array( 'hooks' => array("edit","save"), 'trigger' => 'true', 'triggerFields' => array('fruits_c'), 'onload' => true, 'actions' => array( array( 'name' => 'SetOptions', 'params' => array( 'target' => 'fruits_c', 'keys' => "createList(fruitInSeason())", 'labels' => "createList(fruitInSeason())" ), ), ), );
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetOptions/index.html
980e6d78d8ef-6
), ), ), ); The createList() function is a JavaScript function from Sidecar.  It requires a comma delimited quote enclosed list of options.  We only want this to affect EditViews and Saves, not normal record views since they need to be able to display all fruits and not a truncated list of them.  So we make the 'hooks' array 'hooks' => array("edit","save"), 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 ('Leads' vs. 'Lead') and that the name of the dependency, "setoptions_fruit" in this example, is unique. Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetOptions/index.html
ae1b20dd24c4-0
SetVisibility Overview The SugarLogic SetVisibility action, located in ./include/Expressions/Actions/VisibilityAction.php , is used to determine the visibility logic of a field 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. SetVisibility Parameters Parameter Type Description target String The name of the field to target for visibility. value String
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetVisibility/index.html
ae1b20dd24c4-1
target String The name of the field to target for visibility. value String This parameter can accept a boolean formula or true and false values.  Normally you would put aSugarLogic formula here to set the boolean. For more information on the various parameters in the dependency definitions, please refer to the dependency actions documentation. Examples The follow sections outline the various ways this dependency can be implemented.  SetVisibility Dependency Extensions For our example, we will create a dependency on the Accounts module that shows the phone_alternate field when the phone_office field has been populated. An example is shown below. ./custom/Extension/modules/<module>/Ext/Dependencies/custom_phone_alternate.php <?php $dependencies['Accounts']['phone_alternate_hide'] = array(
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetVisibility/index.html
ae1b20dd24c4-2
$dependencies['Accounts']['phone_alternate_hide'] = array( 'hooks' => array("edit"), 'triggerFields' => array('phone_office'), 'onload' => true, //Actions is a list of actions to fire when the trigger is true 'actions' => array( array( 'name' => 'SetVisibility', 'params' => array( 'target' => 'phone_alternate', 'value' => 'not(equal($phone_office,""))', ), ), ), ); Once you have the file in place, you will need to navigate to Admin > Repairs > and run a Quick Repair and Rebuild.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetVisibility/index.html
ae1b20dd24c4-3
Note: It is important that the module name is plural ('Accounts' vs. 'Account') and that the name of the dependency, "phone_alternate_hide" in this example, is unique.  Visibility Dependencies in Field Definitions Unlike several of the other dependencies, SetVisibility is built into Studio.  So this dependency can be set as a custom vardef value or in the varefs file for a new module. If you wanted to add this dependency to an existing field then you could add a file to ./custom/Extension/modules/<module>/Ext/Vardefs/. An example is shown below. To accomplish this, we will create an extension in ./custom/Extension/modules/Accounts/Ext/Vardefs/.  ./custom/Extension/modules/Accounts/Ext/Vardefs/phone_alternate.php
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetVisibility/index.html
ae1b20dd24c4-4
<?php $dictionary['Account']['fields']['phone_alternate']['dependency']='not(equal($phone_office,"")) Next, you will need to navigate to Admin > Repairs > and run a Quick Repair and Rebuild. Once that is done, you can enter a value into phone_office and the phone_alternate field will show up once you tab out of the phone_office field. If you were coding a custom module with new fields, then you would just include it in the modules vardefs.php file as shown below <?php $dictionary['myModule'] = array( ... 'fields' => array( ... 'phone_alternate' => array( 'name' => 'phone_alternate',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetVisibility/index.html
ae1b20dd24c4-5
'name' => 'phone_alternate', 'vname' => 'LBL_PHONE_ALTERNATE', 'type' => 'varchar', 'len' => 10, 'dependency'=> 'not(equal($phone_office,""))', 'comment' => 'Other Phone Number', 'merge_filter' => 'enabled', ), ... ) ... ); Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetVisibility/index.html
65f240c9b31e-0
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
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/ReadOnly/index.html
65f240c9b31e-1
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 aSugarLogic 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:Â
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/ReadOnly/index.html
65f240c9b31e-2
./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(
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/ReadOnly/index.html
65f240c9b31e-3
'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 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)',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/ReadOnly/index.html
65f240c9b31e-4
'value' => 'equal($lock_record_c,true)', to be: 'value' => 'true', Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/ReadOnly/index.html
ae18242c6523-0
SetPanelVisibility Overview The SugarLogic SetPanelVisibility action, defined in ./include/Expressions/Actions/PanelVisibilityAction.php, is used to determine the visibility of a record view panel 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. SetPanelVisibility Parameters Parameter Type Description target String The id of the panel to hide value String Formula used to determine if the panel should be visible.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetPanelVisibility/index.html
ae18242c6523-1
value String Formula used to determine if the panel should be visible. 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 hide a specific panel if the status field on a case is set to "Closed". Our example extension definition is shown below:  ./custom/Extension/modules/<module>/Ext/Dependencies/hide_panel_2_dep.php <?php $dependencies['Cases']['panel_2_visibility'] = array( 'hooks' => array("edit","view"), 'trigger' => 'equal($status, "Closed")', 'triggerFields' => array('status'), 'onload' => true,
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetPanelVisibility/index.html
ae18242c6523-2
'onload' => true, //Actions is a list of actions to fire when the trigger is true 'actions' => array( array( 'name' => 'SetPanelVisibility', 'params' => array( 'target' => 'detailpanel_2', 'value' => 'true', ), ) ), //notActions is a list of actions to fire when the trigger is false 'notActions' => array( array( 'name' => 'SetPanelVisibility', 'params' => array( 'target' => 'detailpanel_2', 'value' => 'false', ), ), ), );
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetPanelVisibility/index.html
ae18242c6523-3
'value' => 'false', ), ), ), ); 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, "panel_2_visibility" in this example, is unique.   Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetPanelVisibility/index.html
7ea7ef7247ea-0
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.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetRequired/index.html
7ea7ef7247ea-1
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(
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetRequired/index.html
7ea7ef7247ea-2
'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. Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetRequired/index.html
3475fa20b9f6-0
SetValue Overview The SugarLogic SetValue action, located in ./include/Expressions/Actions/SetValueAction.php, is used to set the value of a field 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. SetValue Parameters Parameter Type Description target String The name of the field to target for visibility. value String SugarLogic formula used to get the value for the target field.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetValue/index.html
3475fa20b9f6-1
value String SugarLogic formula used to get the value for the target field. For more information on the various parameters in the dependency definitions, please refer to the dependency actions documentation. Examples The follow sections outline the various ways this dependency can be implemented. Dependency Extensions For our example, we will create a dependency on the Leads module that will display the number of activities related to a Lead.  Activities are composed of calls, meetings, tasks, notes, and emails. An example extension definition is shown below: ./custom/Extension/modules/<module>/Ext/Dependencies/custom_phone_alternate.php <?php $dependencies['Leads']['activity_count_dep'] = array( 'hooks' => array("edit", "view"), //not including save so that the value isn't stored in the DB
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetValue/index.html
3475fa20b9f6-2
'trigger' => 'true', //Optional, the trigger for the dependency. Defaults to 'true'. 'onload' => true, //Whether or not to trigger the dependencies when the page is loaded 'actions' => array( array( 'name' => 'SetValue', 'params' => array( 'target' => 'activity_count_c', 'value' => 'add( count($notes), count($calls), count($emails), count($meetings), count($tasks) )' ) ) ) ); Once you have the file in place, you will need to navigate to Admin > Repairs > and run a Quick Repair and Rebuild.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetValue/index.html
3475fa20b9f6-3
Note: It is important that the module name is plural ('Cases' vs. 'Case') and that the name of the dependency, "activity_count_dep" in this example, is unique. Chaining Dependencies You can also add as many actions as you need to the array. In the example below, we want to display our count value but prevent users from being able to edit the value. An example extension definition is shown below: <?php $dependencies['Leads']['number_of_cases_dep'] = array( 'hooks' => array("edit", "view"), //not including save so that the value isn't stored in the DB 'trigger' => 'true', //Optional, the trigger for the dependency. Defaults to 'true'.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetValue/index.html
3475fa20b9f6-4
//'triggerFields' => array('status'), //unneeded for this example as its not field triggered 'onload' => true, 'actions' => array( array( 'name' => 'SetValue', 'params' => array( 'target' => 'activity_count_c', 'value' => 'add( count($notes), count($calls), count($emails), count($meetings), count($tasks) )' ) ), array( 'name' => 'ReadOnly', 'params' => array( 'target' => 'activity_count_c', 'value' => 'true', //Set to true instead of a formula because its always read-only ), ) ) );
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetValue/index.html
3475fa20b9f6-5
), ) ) ); 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, "number_of_cases_dep" in this example, is unique. Dependencies in Field Definitions
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetValue/index.html
3475fa20b9f6-6
Dependencies in Field Definitions Unlike several of the other dependencies, SetValue is built into Studio.  So this dependency can be set as a custom vardef value or in the vardefs file of a custom module.  If you wanted to add this dependency to an existing field then you can create a vardef extension such as ./custom/Extension/modules/<module>/Ext/Vardefs/. An example extension definition is shown below: ./custom/Extension/modules/Accounts/Ext/Vardefs/activity_count_c.php <?php $dictionary['Lead']['fields']['activity_count_c']['options'] = 'numeric_range_search_dom';
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetValue/index.html
3475fa20b9f6-7
$dictionary['Lead']['fields']['activity_count_2_c']['calculated'] = 'true'; $dictionary['Lead']['fields']['activity_count_2_c']['formula'] = 'add( count($calls), count($emails), count($meetings), count($notes), count($tasks) )'; $dictionary['Lead']['fields']['activity_count_2_c']['enforced'] = 'true'; $dictionary['Lead']['fields']['activity_count_2_c']['enable_range_search'] = '1'; Once you have the file in place, you will need to navigate to Admin > Repairs > and run a Quick Repair and Rebuild. Â
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetValue/index.html
3475fa20b9f6-8
  Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Dependency_Actions/SetValue/index.html
0785a54f8349-0
Extending Sugar Logic Overview How to write custom Sugar Logic functions. Writing a Custom Formula Function The most important feature of Sugar Logic is that it is simply and easily extendable. Both custom formula functions and custom actions can be added in an upgrade-safe manner to allow almost any custom logic to be added to Sugar. Custom functions will be stored in ./custom/include/Expressions/Expression/{Type}/{Function_Name}.php.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Extending_Sugar_Logic/index.html
0785a54f8349-1
The first step in writing a custom function is to decide what category the function falls under. Take, for example, a function for calculating the factorial of a number. In this case, we will be returning a number so we will create a file in ./custom/include/Expressions/Expression/Numeric/ called FactorialExpression.php. In the new PHP file we just created, we will define a class called FactorialExpression that will extend NumericExpression. All formula functions must follow the format {functionName}Expression.php and the class name must match the file name. Next, we need to decide what parameters the function will accept. In this case, we need take in a single parameter, the number to return the factorial of. Since this class will be a sub-class of NumericExpression, it by default accepts only numeric types and we do not need to worry about specifying the type requirement.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Extending_Sugar_Logic/index.html
0785a54f8349-2
Next, we must define the logic behind evaluating this expression. So we must override the abstract evaluate() function. The parameters can be accessed by calling an internal function getParameters() which returns the parameters passed into this object. So, with all this information, we can go ahead and write the code for the function. Note: For the custom function to appear in Studio after completing these steps, you must compile your code by running the Rebuild Sugar Logic Functions job in Admin > Schedulers and then clear your browser cache. <?php require_once 'include/Expressions/Expression/Numeric/NumericExpression.php'; class FactorialExpression extends NumericExpression { function evaluate() { $params = $this->getParameters(); // params is an Expression object, so evaluate it // to get its numerical value $number = $params->evaluate(); // exception handling
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Extending_Sugar_Logic/index.html
0785a54f8349-3
$number = $params->evaluate(); // exception handling if ( ! is_int( $number ) ) { throw new Exception("factorial: Only accepts integers"); } if ( $number < 0 ) { throw new Exception("factorial: The number must be positive"); } // special case 0! = 1 if ( $number == 0 ) return 1; // calculate the factorial $factorial = 1; for ( $i = 2 ; $i <= $number ; $i ++ ) { $factorial = $factorial * $i; } return $factorial; } // Define the javascript version of the function static function getJSEvaluate() { return <<<EOQ
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Extending_Sugar_Logic/index.html
0785a54f8349-4
static function getJSEvaluate() { return <<<EOQ var params = this.getParameters(); var number = params.evaluate(); // reg-exp integer test if ( ! /^\d*$/.test(number) ) throw "factorial: Only accepts integers"; if ( number < 0 ) throw "factorial: The number must be postitive"; // special case, 0! = 1 if ( number == 0 ) return 1; // compute factorial var factorial = 1; for ( var i = 2 ; i <= number ; i ++ ) factorial = factorial * i; return factorial; EOQ; } function getParameterCount() { return 1; // we only accept a single parameter }
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Extending_Sugar_Logic/index.html
0785a54f8349-5
{ return 1; // we only accept a single parameter } static function getOperationName() { return "factorial"; // our function can be called by 'factorial' } } ?> One of the key features of Sugar Logic is that the functions should be defined in both PHP and JavaScript and have the same functionality under both circumstances. As you can see above, the getJSEvaluate() method should return the JavaScript equivalent of your evaluate() method. The JavaScript code is compiled and assembled for you after you run the "Rebuild Sugar Logic Functions" script through Admin > Schedulers. Writing a Custom Action
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Extending_Sugar_Logic/index.html
0785a54f8349-6
Writing a Custom Action Using custom actions, you can easily create reusable custom logic or integrations that can include user-editable logic using the Sugar Formula Engine. Custom actions will be stored in ./custom/include/Expressions/Actions/{ActionName}.php. Actions files must end in Action.php and the class defined in the file must match the file name and extend the AbstractAction class. The basic functions that must be defined are fire, getDefinition, getActionName, getJavascriptClass, and getJavscriptFire. Unlike functions, there is no requirement that an action works exactly the same for both server and client side as this is not always sensible or feasible.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Extending_Sugar_Logic/index.html
0785a54f8349-7
A simple action could be "WarningAction" that shows an alert warning the user that something may be wrong and logs a message to the ./sugarcrm.log file if triggered on the server side. It will take in a message as a formula so that the message can be customized at runtime. We would do this by creating a PHP file in ./custom/include/Expressions/Actions/WarningAction.php as shown below: ./custom/include/Expressions/Actions/WarningAction.php <?php require_once("include/Expressions/Actions/AbstractAction.php"); class WarningAction extends AbstractAction { protected $messageExp = ""; /** * Returns the javascript class equavalent to this php class * @return string javascript. */ static function getJavascriptClass() { return <<<EOQ
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Extending_Sugar_Logic/index.html
0785a54f8349-8
static function getJavascriptClass() { return <<<EOQ SUGAR.forms.WarningAction = function(message) { this.messageExp = message; }; //Use the sugar extend function to extend AbstractAction SUGAR.util.extend(SUGAR.forms.WarningAction, SUGAR.forms.AbstractAction, { //javascript exection code exec : function() { //assume the message is a formula var msg = SUGAR.forms.evalVariableExpression(this.messageExp); alert(msg.evaluate()); } }); EOQ; } /** * Returns the javascript code to generate this actions equivalent. * @return string javascript. */ function getJavascriptFire()
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Extending_Sugar_Logic/index.html
0785a54f8349-9
* @return string javascript. */ function getJavascriptFire() { return "new SUGAR.forms.WarningAction('{$this->messageExp}')"; } /** * Applies the Action to the target. * @param SugarBean $target */ function fire(&$target) { //Parse the message formula and log it to fatal. $expr = Parser::replaceVariables($this->messageExp, $target); $result = Parser::evaluate($expr)->evaluate(); $GLOBALS['log']->warn($result); } /** * Returns the definition of this action in array format. */ function getDefinition() { return array("message" => $this->messageExp); } /**
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Extending_Sugar_Logic/index.html
0785a54f8349-10
return array("message" => $this->messageExp); } /** * Returns the short name used when defining dependencies that use this action. */ static function getActionName() { return "Warn"; } } ?> Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Sugar_Logic/Extending_Sugar_Logic/index.html
9bedf6bf84d1-0
This page refers to beta functionality. Please be advised that the content of this page is subject to change. CLI Overview Sugar on-premise deployments include a command line interface tool built using the Symfony Console Framework. Sugar's CLI is intended to be an administrator or developer level power tool to execute PHP code in the context of Sugar's code base. These commands are version specific and can be executed on a preinstalled Sugar instance or on an installed Sugar instance. Sugar's CLI is not intended to be used as a tool to interact remotely with an instance nor is it designed to interact with multiple instances.  Commands Sugar Commands are an implementation of Console Commands. They extend the base console classes to execute Sugar specific actions. Each instance of Sugar is shipped with a list of predefined commands. The current list of commands is shown below. Command Description help Displays help for a command
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html
9bedf6bf84d1-1
Command Description help Displays help for a command list Lists commands aclcache:dump Dumps ACL cache contents into cache/acldumps folder elastic:explain Execute global search explain queries for debugging purposes. As this will generate a lot of output in JSON format, it is recommended to redirect the output to a file for later processing elastic:indices Show Elasticsearch index statistics elastic:queue Show Elasticsearch queue statistics elastic:queue_cleanup Cleanup records from Elasticsearch queue elastic:refresh_enable Enable refresh on all indices elastic:refresh_status Show Elasticsearch index refresh status elastic:refresh_trigger Perform a manual refresh on all indices elastic:replicas_enable Enable replicas on all indices elastic:replicas_status Show Elasticsearch index refresh status elastic:routing
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html
9bedf6bf84d1-2
Show Elasticsearch index refresh status elastic:routing Show Elasticsearch index routing idm-mode:manage enable, disable IDM mode, or move config data to DB password:config Show password hash configuration password:reset Reset user password for local user authentication password:weak Show users having weak or non-compliant password hashes search:fields Show search engine enabled fields search:module Enable/disable given module for search search:reindex Schedule SearchEngine reindex search:silent_reindex Create mappings and index the data search:silent_reindex_mp Create mappings and index the data using multi-processing search:status Show search engine availability and enabled modules team-security:rebuild Rebuild denormalized team security data team-security:status Display the status of the denormalized data
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html
9bedf6bf84d1-3
team-security:status Display the status of the denormalized data teamset:backup Backs up the team_sets related tables teamset:prune Prune all team set tables of unused team sets. Original tables will be backed up automatically. DO NOT USE while users are logged into the system teamset:restore_from_backup Restores all team set tables from backups. DO NOT USE while users are logged into the system teamset:scan Scan all module tables for unused team sets and report the number found teamset:sql Print the sql query used to search for unused teamsets Note : For advanced users, a bash autocompletion script for CLI is located at ./src/Console/Resources/sugarcrm-bash-completion for inclusion in  ~/.bashrc. More details on using the script can be found in the file's header comments. Usage
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html
9bedf6bf84d1-4
Usage The command executable, located at ./bin/sugarcrm, is executed from the root of the Sugar instance. The command signature is shown below: php bin/sugarcrm <command> [options] [arguments] Help The command console has built-in help documentation. If you pass in a command that isn't found, you will be shown the default help documentation.  SugarCRM Console version <version> Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html
9bedf6bf84d1-5
-n, --no-interaction Do not ask any interactive question --profile Display timing and memory usage information -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: help Displays help for a command list Lists commands aclcache aclcache:dump Dumps ACL cache contents into cache/acldumps folder. elastic elastic:explain Execute global search explain queries for debugging purposes. As this will generate a lot of output in JSON format, it is recommended to redirect the output to a file for later processing. elastic:indices Show Elasticsearch index statistics elastic:queue Show Elasticsearch queue statistics elastic:queue_cleanup Cleanup records from Elasticsearch queue.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html
9bedf6bf84d1-6
elastic:queue_cleanup Cleanup records from Elasticsearch queue. elastic:refresh_enable Enable refresh on all indices elastic:refresh_status Show Elasticsearch index refresh status elastic:refresh_trigger Perform a manual refresh on all indices elastic:replicas_enable Enable replicas on all indices elastic:replicas_status Show Elasticsearch index refresh status elastic:routing Show Elasticsearch index routing idm-mode idm-mode:manage enable, disable IDM mode, or move config data to DB password password:config Show password hash configuration password:reset Reset user password for local user authentication. password:weak Show users having weak or non-compliant password hashes search search:fields Show search engine enabled fields
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html
9bedf6bf84d1-7
search search:fields Show search engine enabled fields search:module Enable/disable given module for search search:reindex Create mappings and schedule a reindex search:silent_reindex Create mappings and index the data search:silent_reindex_mp Create mappings and index the data using multi-processing search:status Show search engine availability and enabled modules team-security team-security:rebuild Rebuild denormalized team security data team-security:status Display the status of the denormalized data teamset teamset:backup Backs up the team_sets related tables. teamset:prune Prune all team set tables of unused team sets. Original tables will be backed up automatically. DO NOT USE while users are logged into the system!
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html
9bedf6bf84d1-8
teamset:restore_from_backup Restores all team set tables from backups. DO NOT USE while users are logged into the system! teamset:scan Scan all module tables for unused team sets and report the number found. teamset:sql Print the sql query used to search for unused teamsets  Additional help documentation is also available for individual commands. Some examples of accessing the help are shown below.  Passing the word "help" before a command name: php bin/sugarcrm help <command> Passing the "-h" option: php bin/sugarcrm <command> -h An example of the list help documentation is shown below. Usage: list [options] [--] [] Arguments: namespace The namespace name Options: --xml To output list as XML
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html
9bedf6bf84d1-9
namespace The namespace name Options: --xml To output list as XML --raw To output raw command list --format=FORMAT The output format (txt, xml, json, or md) [default: "txt"] Help: The list command lists all commands: php bin/sugarcrm list You can also display the commands for a specific namespace: php bin/sugarcrm list test You can also output the information in other formats by using the --format option: php bin/sugarcrm list --format=xml It's also possible to get raw list of commands (useful for embedding command runner): php bin/sugarcrm list --raw Custom Commands
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html
9bedf6bf84d1-10
php bin/sugarcrm list --raw Custom Commands Sugar allows developers the ability to create custom commands. These commands are registered using the Extension Framework. Each custom command will extend the stock Command class and implement a specific mode interface. The file system location of the command code can exist anywhere in the instance's file system including a separate composer loaded repository.  Best Practices The following are some common best practices developers should keep in mind when adding new commands : Do not extend from existing commands Do not duplicate an already existing command Pick the correct mode for the command Limit the logic in the command Do not put reusable components in the command itself Each command requires specific sections of code in order to properly create the command. These requirements are listed in the sections below. Command Namespace
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html
9bedf6bf84d1-11
Command Namespace It is recommended to name any custom commands using a proper "command namespace". These namespaces are different than PHP namespaces and reduce the chances of collisions occurring between vendors. An example of this would be to prefix any commands with a namespace format of vendor:category:command E.g. MyDevShop:repairs:fixMyModule Note : The CLI framework does not allow overriding of existing commands. PHP Namespace The header of the PHP command file will need to define the following namespace: namespace Sugarcrm\Sugarcrm\custom\Console\Command; In addition to the namespace, the following use commands are required for different operations : Name Description Example Command Every command will extend the Command class use Symfony\Component\Console\Command\Command; Mode Whether the command is an Instance or Standalone Mode command
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html
9bedf6bf84d1-12
Mode Whether the command is an Instance or Standalone Mode command use Sugarcrm\Sugarcrm\Console\CommandRegistry\Mode\InstanceModeInterface; use Sugarcrm\Sugarcrm\Console\CommandRegistry\Mode\StandaloneModeInterface; Input Accepts Input from the command use Symfony\Component\Console\Input\InputInterface; Output Sends Output from the command use Symfony\Component\Console\Output\OutputInterface; Mode When creating Sugar commands, developers will need to specify the mode or set of modes for the command. These modes help prepare the appropriate resources for execution of the command.  Mode Description Instance Mode  Commands that require an installed Sugar instance. Standalone Mode  Commands that do not require an installed Sugar instance.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html
9bedf6bf84d1-13
Standalone Mode  Commands that do not require an installed Sugar instance. Note : Multiple modes can be selected. Class Definition The custom command class definition should extend the stock command class as well as implement a mode's interface.  // Instance Mode Class Definition class <classname> extends Command implements InstanceModeInterface { //protected methods } // Standalone Mode Class Definition class <classname> extends Command implements StandaloneModeInterface { //protected methods } // Implementing both Modes class <classname> extends Command implements InstanceModeInterface, StandaloneModeInterface { //protected methods } Methods Each command class implements two protected methods : Method Description configure()  Runs on the creation of the command. Useful to set the name, description, and help on the command.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html
9bedf6bf84d1-14
execute(InputInterface $input, OutputInterface $output)  The code to run for executing the command. Accepts an input and output parameter.  An example of implementing the protected methods is shown below: protected function configure() { $this->setName('sugardev:helloworld') ->setDescription('Hello World') ->setHelp('This command accepts no paramters and returns "Hello World".') ; } protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln("Hello world -> " . $this->getApplication()->getMode()); } Registering Command After creating the custom command file, register it with the Extension Framework. This file will be located in ./custom/Extension/application/Ext/Console/. An example of registering a command is below:
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/CLI/index.html