Let the platform do the work

Calculated Field - Copying Dropdown Value to a Text Field

Overview

This article will walk through how to use the getDropdownValue() function in a Sugar Logic formula to copy a value from a dropdown field into a custom text field.

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 the value of "Customer" in the Account Type dropdown field into a new text field. With our first formula, we will copy the value to a new field on the same module so that our account type can be mirrored on the second tab of the Accounts detailview even though the original field is only present on the first tab. We will also create a second formula that copies the field value to a different, related module. This will copy the account type to a field on the related Contacts module so that each contact record will display the account type of its related Account.

Prerequisites

You will need a dropdown field that is populated for your test record. You will also need to create a new field of type TextField and mark it as calculated before entering the following formula.

Formula

The formula below will copy the value in the Account Type field to the new text field on the Accounts module.

getDropdownValue("account_type_dom",$account_type)

If you would like the value of the dropdown field copied into a new text field in a different module, you can enter the formula below.

getDropdownValue("account_type_dom",related($accounts,"account_type"))

Formula Breakdown

The getDropdownValueDropdown() function in the first formula returns the display value of the option currently selected for Account Type. This function first requires the name of the dropdown which can be found by looking in Studio > {Module Name} > Fields > {Dropdown Field} > Drop Down List. The second input is the dropdown itself. For our example, the formula will write "Customer" into the new text field since the Account Type field has a display value of "Customer" selected.

For the second formula, we still need to provide the getDropdownValue() formula with the dropdown field. Since that field does not exist on our new text field's module but rather on a related module, we will use the related() function to reach across to the related module and access the desired field. The related() function needs 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 Studio's Formula Builder's Related Field button to produce the right module or relationship name. For our example, all Contacts related to this Account will show "Customer" in their new text field.

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 dropdown field.
Image_1New 
rest/v11/doc_PagesFiles/10e806ef-175c-4bb1-e6eb-55022f9bcfc8/file/uploadfile?force_download=0&platform=base