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.
Amongst some methods, I prefer using the below to retrieve the OptionSet Value i.e. the code itself
- Lets say I’m looping through a list of records retrieved using RetrieveMultiple in my plugin.
entity.GetAttributeValue<OptionSetValue>("field_name").Value;to retrieve the value of the OptionSet option and store it in an Int32 / int variable.
- 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 –
- 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.
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 –
- Select the item based on a key value using Filter Array in Power Automate
- Select values from an array using Select action in a Power Automate Flow
- Blocking Attachment Extensions in Dynamics 365 CRM
- Upgrade Dataverse for Teams Environment to Dataverse Environment
- Showing Sandbox or Non Production Apps in Power App mobile app
- Create a Power Apps Per User Plan Trial | Dataverse environment
- Install On-Premise Gateway from Power Automate or Power Apps | Power Platform
- Co-presence in Power Automate | Multiple users working on a Flow
- Search Rows (preview) Action in Dataverse connector in a Flow | Power Automate
- Suppress Workflow Header Information while sending back HTTP Response in a Flow | Power Automate
- Call a Flow from Canvas Power App and get back response | Power Platform\
- FetchXML Aggregation in a Flow using CDS (Current Environment) connector | Power Automate
- Parsing Outputs of a List Rows action using Parse JSON in a Flow | Common Data Service (CE) connector
- Asynchronous HTTP Response from a Flow | Power Automate
- Validate JSON Schema for HTTP Request trigger in a Flow and send Response | Power Automate
- Converting JSON to XML and XML to JSON in a Flow | Power Automate