Dependent Fields use Sugar Logic to control the fields’ visibility so that they are only shown when certain conditions are met. Administrators can create these formulas via Studio or Module Builder when editing a field by selecting the Dependent checkbox and using formula builder. This article will present an example formula for a dependent field that only appears when a field on the record matches a list of acceptable values.
For an overview on Sugar Logic and Calculated Fields, please refer to the article Introduction to Calculated Fields.
In this example, we will make the custom Status field in the Accounts module appear only if the Account Type field equals one of the three listed specified values: Customer, Partner, or Investor.
You will need to create a new field of type TextField in the Accounts module and mark it as a dependent field before entering the following formula.
The dependent formula below will make the Status field visible in the edit and detailview of the Account module only if the selected value of the dropdown Type field equals either Customer, Partner or Investor.
The createList() function creates a temporary list of string values that we will use to compare. We then use the isInList() function check if the value of the account_type field appears in the temporary list. Since account_type is a dropdown field, isInList() will use the selected option’s item name (as opposed to its display label) as the comparison value. You can see the item names and display labels for all options within a dropdown menu in Admin > Dropdown Editor.
If account_type’s selected option has an item name of “Customer”, “Partner”, or “Investor”, then the formula will return “true”, thus causing the dependent Status field to be displayed.
For our example, the createList() function generates a temporary list of values (Customer, Partner, Investor), and the isInList() function compares the list to the Type field’s value. Since the item name of the account’s selected type is “Customer”, the condition is met and the Status field will be visible.
Once your custom text field is created with the dependency formula and added to the module’s edit and detailview, the dependent field will appear if the type field contains one of the value in your specified list. For our example, the Status field is visible since the Account Type field has a display value of “Customer”.