Let the platform do the work

Calculated Field - Copying a Field From a Custom Module

Overview

This article will walk through how to use the related() function in a Sugar Logic formula to copy a field value from a related module into a field in the current module.

For an overview on Sugar Logic and Calculated Fields, please refer to the article Introduction to Calculated Fields.

Use Case

In this example, we will copy our custom Partners module's Office Phone field to a new text field on the Accounts module.

Prerequisites

You will need to have an existing custom module or create a new one via Module Builder. We created a custom module called "Partners" with a one-to-one relationship ("a_partners_accounts") to the Accounts module. For more information on creating custom modules, please refer to Module Loader documentation specific to your Sugar product and version. Please note that there must be a relationship defined between the custom module and the module containing the calculated field.

The specified field in the related custom module record must be populated with a value. You will need to create a new field of type TextField in your target module and mark it as calculated before entering the following formula.

Formula

The formula below will copy the value of the Office Phone field in the Partners module into the new text field in the Accounts module.

related($a_partners_accounts,"phone_work")

Formula Breakdown

The related() function returns the value of the specified field in the related module.

For our example, the related() function reaches across to the related Partners module to access the Office Phone field and returns the value, 404-555-1234, to the custom text field. The related() function needs both the relationship name as well as the desired field's name in order to return the proper value. You can use Studio's Formula Builder's Related Field button to produce the correct relationship name.

Application

Once your custom text field is created with the calculated value formula and added to the module's detailview, it will display the value of the related custom module's specified field. For our example, the related partner's phone number will be displayed in the custom text field of the Account record. Because OTC Holdings (the example account) is related to Thomas Adams ( the partner), the formula is able to retrieve the office phone number from Thomas' record and copy it into the Partners Phone field on the Account record.
rest/v11/doc_PagesFiles/4fc9d068-6014-870f-8dfc-55027f72fed1/file/uploadfile?force_download=0&platform=base