Sugar Logic enables administrators to create business logic for field calculations without needing to write PHP code. The field’s dynamic value will be automatically updated based on a calculation you provide. This article will walk through how to use the related() function in a Sugar Logic formula to automatically pull a related contact’s phone number into a custom field in the Calls module.
Sally wants to make sure that when she creates a call that is related to a contact, the contact’s mobile phone number is pulled into her custom field (e.g. Contact Mobile Phone) on the call record.
You will need to be familiar with the following actions, which are not explained in this article:
- Adding fields via Admin > Studio
- Modifying layouts via Admin > Studio
For more information about accomplishing each of these, please refer to the Studio documentation.
Before building the formula, we will need to add a new field to the Calls module with the following settings:
- Type : Phone
- Field Name : contact_mobile_phone (this field cannot contain any spaces)
- Field Label : Contact Mobile Phone
The other field options are not required, but we will be returning to this field later.
You will need to add this new field to the call’s edit view and record view layout.
Use the following steps to add a Sugar Logic formula which automatically pulls a related contact’s phone number into the custom field on the Calls module:
- Navigate to Admin > Studio > Calls > Fields > Contact Mobile Phone.
- Check the Calculated Value checkbox, and click the Edit Formula button to enter the calculation.
- Click the Related Field button on the upper left of the Formula Builder popup box.
- Select “Contacts” as the module and “Mobile” as the field in the dropdown list. Click “Insert”.
- Once the related formula appears, click “Save” then save the Contact Mobile Phone field on the Edit Field tab.
The Contact Mobile Phone field is now ready to display the related contact’s phone number in the call’s detail view. Please note that you must add the field to the Calls module’s detailview, editview, etc. in order to view the information. Please refer to the Application section of this article to view this calculated field in action.
phone_mobile field from the Contacts module needs to be accessed, the
related() function is used to reach across to the related module and access the desired field. The
related() function requires both the module name (or relationship name in the case of a custom relationship), as well as the desired field’s name. You can use the Formula Builder’s Related Field button in Studio to produce the correct module or relationship name.
Once the Contact Mobile Phone field is saved with the calculated value formula, navigate to the Calls module to create a new call. Relate the call to a contact (e.g. Jane Smith) with an existing mobile phone number then save the record. The Contact Mobile Phone field on the call’s record will automatically populate with the value from the contact’s