Dataverse Choice & Choices Conversion in Power Automate
Well its been a while since I blogged about Choice(s)/(Multi-select) Option Sets/Picklists so its time to (finally) share how you can create a very helpful child flow that will help you convert Choice or Choices column values from Label to Value and also Value to label for any table or column in Dataverse. You can call this child flow from any other flow you are building when a choice or Choices conversion is required.
I previously posted about Converting Dataverse Choice(s), (Multi-select) Option Sets, or Picklists in Power Automate with Custom Actions but I know that installing third-party solutions is not always feasible depending on the governance and rules your organisation is run under. It makes sense and it’s a perfect excuse to smugly build your own Dataverse Choice & Choices Conversion flow instead.
Roll on down to the bottom for an ended to end image of the flow steps and also some examples of the data conversions you can do.
Create your flow inside a solution
This is a life rule always, but particularly in the case of child flows. If you don’t put your magical conversion child flow inside a solution, then you will not be able to use it as part of other flows (which also need to be inside a solution). The solution is to always use a solution. Ok I’m done preaching now, lets begin!
https://@{urihost(body('GetODataURI')?['@odata.context']) }/api/data/v9.2/EntityDefinitions(LogicalName='@{triggerBody()['text_1']}')/Attributes(LogicalName='@{triggerBody()['text']}')
Reminder to use HTTP with Microsoft Entra ID (preauthorized)
@{outputs('MetadataBaseURL')}/@{outputs('Datatype')}?$select=LogicalName,SchemaName,AttributeTypeName&$expand=OptionSet($select=Options)
Educational interlude
if(equals(triggerBody()['text_2'],'Label to Value'), split(replace(triggerBody()['text_3'],'; ',';'),';'), split(replace(triggerBody()['text_3'],', ',','),',') )
Add a condition to check the conversion type
Depending on if we are converting Label to Value or Value to label we need to search the reference data differently. Add a new action Control > Condition
Action Name: Label to Value
Condition: (below)
triggerBody()['text_2'] is equal to Label to Value
If yes, filter on the label
In the Yes branch of the condition, add a new action Data Operation > Filter Array
Action Name: FilterChoicesLabelToValue
From: (below)
body('GetChoiceMetadata')?['OptionSet']?['Options']
Condition: (below)
item()?['Label']?['UserLocalizedLabel']?['Label'] is equal to items('EachValueOrLabel')
coalesce(first(body('FilterChoicesLabelToValue'))?['Value'], -1)
If no, filter on the value
In the No branch of the condition, add a new action Data Operation > Filter Array
Action Name: FilterChoicesValueToLabel
From: (below)
body('GetChoiceMetadata')?['OptionSet']?['Options']
Condition: (below)
item()?['Value'] is equal to int(items('EachValueOrLabel'))
coalesce(first(body('FilterChoicesValueToLabel'))?['Label']?['UserLocalizedLabel']?['Label'],'')
Tidy up the response string
After the apply to each loop, we need to tidy up the string to remove any trailing commas or semicolons and spaces. Add a new action Data Operation > Compose
Action Name: RemoveTrailingCharacters
Inputs: (below)
substring(variables('Response'),0,sub(length(variables('Response')),if(equals(triggerBody()['text_2'],'Label to Value'),1,2)))
Respond with the converted Label or Value
The magic is done, now to send back the answer to to the parent flow with the converted value or label. Add a new PowerApps > Respond to a PowerApp or flow action.
Add the following outputs:
Type: Number
Title: Label to Value Response - Single Choice Only
Value: below)
if(and(equals(triggerBody()['text_2'],'Label to Value'),equals(outputs('Datatype'),'Microsoft.Dynamics.CRM.PicklistAttributeMetadata')),int(coalesce(outputs('RemoveTrailingCharacters'), -1)),null)
Type: Text
Title: Value to Label Response
Value: (below)
if(equals(triggerBody()['text_2'],'Value to Label'),outputs('RemoveTrailingCharacters'),null)
Type: Text
Title: Label to Value Response - Multiple Choice
Value: (below)
if(and(equals(triggerBody()['text_2'],'Label to Value'),equals(outputs('Datatype'),'Microsoft.Dynamics.CRM.MultiSelectPicklistAttributeMetadata')),outputs('RemoveTrailingCharacters'),null)
Always respond
Just in case anything goes wrong, we always want the flow to respond. Select the ellipsis (…) on the ‘Respond to a PowerApp or flow action’ Choose Configure run after. Update the actions to allow the ‘Respond to a PowerApp or flow’ action to run after any condition - is successful, has failed, is skipped & has timed out.
Test it Manually
One of the many things I love about building child flows is that they are so much easier to test manually by providing inputs without having to create or modify something to trigger the automation.
And also Labels into Values:
Use a child flow inside a flow
Now you can use your child flow by calling it from another flow whenever you need the conversions. Just add the Action Flows > Ran a Child Flow, fill in the value required either statically or dynamically and you are good to go:
Finally, in case you got lost along the way there is an end to end screenshot of the choice & choices conversion flow from the steps above