Read OptionSet Labels in Dynamics 365 CRM Plugins | Entity object

Usually, you’d look at the OptionSet in the customiation and decide to write plugin logic based on the code you have noted down.

But, at times, you might want to know what the OptionSet Labels are for these Options, in that case, here’s how you retrieve the labels as well.

In case you are looking to retrieve OptionSet Labels in Power Automate Flow on the Dataverse connector, you can check this post – Read OptionSet Labels from CDS/Dataverse Triggers or Action Steps in a Flow | Power Automate


Below is the OptionSet Value and you want to retrieve the Label part when you retrieve or work with RetrieveMultiple or object of the Entity class in Dynamics 365 CRM plugin execution context


And here’s the Data that I’ll be retrieving in my plugin of which I need the label “Silver” instead of the OptionSet value of 1 as seen above.

OptionSet Value

Amongst some methods, I prefer using the below to retrieve the OptionSet Value i.e. the code itself

  1. Lets say I’m looping through a list of records retrieved using RetrieveMultiple in my plugin.
    I use entity.GetAttributeValue<OptionSetValue>("field_name").Value; to retrieve the value of the OptionSet option and store it in an Int32 / int variable.

  2. But, this doesn’t give you the Name of the label itself. For that, you’ll need to use a different method. Let’s see below

OptionSet labels using Formatted Values

Below is how you can retrieve Label of the OptionSet value from the Object of the Entity class in Dynamics 365 CRM plugin execution context –

  1. Similar to the above step, I’m retrieving the name of the Label of the same OptionSet value I’m working on from the same example above.
    I use entity.FormattedValues["field_name"]; to retrieve the Label of the OptionSet option and store it in a String / string variable.

Here’s where all the other Formatted Values are stored in the RetrieveMultiple’s Object

And that’s how you retrieve the OptionSet Labels in your Dynamics 365 CRM plugin.

Hope this helps!

Here are some Power Automate posts you want to check out –

  1. Select the item based on a key value using Filter Array in Power Automate
  2. Select values from an array using Select action in a Power Automate Flow
  3. Blocking Attachment Extensions in Dynamics 365 CRM
  4. Upgrade Dataverse for Teams Environment to Dataverse Environment
  5. Showing Sandbox or Non Production Apps in Power App mobile app
  6. Create a Power Apps Per User Plan Trial | Dataverse environment
  7. Install On-Premise Gateway from Power Automate or Power Apps | Power Platform
  8. Co-presence in Power Automate | Multiple users working on a Flow
  9. Search Rows (preview) Action in Dataverse connector in a Flow | Power Automate
  10. Suppress Workflow Header Information while sending back HTTP Response in a Flow | Power Automate
  11. Call a Flow from Canvas Power App and get back response | Power Platform\
  12. FetchXML Aggregation in a Flow using CDS (Current Environment) connector | Power Automate
  13. Parsing Outputs of a List Rows action using Parse JSON in a Flow | Common Data Service (CE) connector
  14. Asynchronous HTTP Response from a Flow | Power Automate
  15. Validate JSON Schema for HTTP Request trigger in a Flow and send Response | Power Automate
  16. Converting JSON to XML and XML to JSON in a Flow | Power Automate

Thank you!