[TIP] How to Get Lookup Field Name and Option Set Field Selected Option's Name in N52 Formulas

 

How to Get Lookup Field Name and Option Set Field Selected Option's Name in N52 Formulas

Introduction

When working with N52 formulas in Dynamics 365, you might need to display the name referenced by a Lookup field or the name of a selected option from an Option Set field. This article aims to guide you through these tasks using N52 formulas.

Getting the Name from a Lookup Field

In N52 formulas, navigating through relationships can fetch specific field values. However, using a field like [kc_mealsdelivered.kc_mealdeliverylocationid.kc_name] may return the GUID by default. To fetch the name instead, you can add a question mark (?) at the end of the field name to enable null propagation or some form of graceful handling of null or empty values.

Example Note:

  • [kc_mealsdelivered.kc_mealdeliverylocationid.kc_name] returns the GUID.
  • [kc_mealsdelivered.kc_mealdeliverylocationid.kc_name.?] returns the name.

Example Formula:

N52 formula
StringConcat( [kc_mealsdelivered.kc_mealdeliverylocationid.kc_name.?], ' - ', GetOptionSetName('kc_mealsdelivered.kc_meal', [kc_mealsdelivered.kc_meal]), ' ', ToString([kc_mealsdelivered.kc_date], 'MM/dd/yyyy') )

Getting the Name of a Selected Option from an Option Set Field

Option Set fields in Dynamics 365 usually store their values as integers. To get the name of the selected option, N52 provides the GetOptionSetName function. This returns the localized string name for a given option set value, based on the user's language settings.

Function Signature:

N52 formula
GetOptionSetName('entitylogicalname.attributelogicalname', 'optionsetvalue')

Example Usage:

N52 formula
GetOptionSetName('opportunity.rating', 1) // Returns 'Hot'

Example Formula to Get Selected Option's Name:

N52 formula
StringConcat( [kc_mealsdelivered.kc_mealdeliverylocationid.kc_name.?], ' - ', GetOptionSetName('kc_mealsdelivered.kc_meal', [kc_mealsdelivered.kc_meal]), ' ', ToString([kc_mealsdelivered.kc_date], 'MM/dd/yyyy') )

In this formula, GetOptionSetName('kc_mealsdelivered.kc_meal', [kc_mealsdelivered.kc_meal]) fetches the name of the selected option in the kc_meal option set.

Conclusion

Using N52 formulas, you can efficiently get the names referenced by Lookup fields and the names of selected options in Option Set fields. This flexibility allows for more readable and informative outputs.

No comments:

Post a Comment