Amey Holden

View Original

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!

See this content in the original post

Reminder to use HTTP with Microsoft Entra ID (preauthorized)

Don’t say that I didn’t remind you!

See this content in the original post
See this content in the original post

Educational interlude

For a bit of context - here is some examples of the data ‘Labels’ and ‘Values’ for Choice & Choices columns

See this content in the original post

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)

See this content in the original post

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)

See this content in the original post

Condition: (below)

See this content in the original post
See this content in the original post

 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)

See this content in the original post

Condition: (below)

See this content in the original post
See this content in the original post

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)

See this content in the original post

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)

See this content in the original post

Type: Text
Title: Value to Label Response
Value: (below)

See this content in the original post

Type: Text
Title: Label to Value Response - Multiple Choice
Value: (below)

See this content in the original post

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.

A good out of the box example to test is the ‘Preferred Method of Contact’ on the Contact table.

Using the above table & column as an example manually test your flow to turn Label into Value:

LogicalNameColumn: preferredcontactmethodcode
LogicalNameTable: contact
Conversion Type: Label to Value
Choice Label or Value: Fax

The same for Choices columns too, for example using the above table & column as an example you can manually test the flow to turn Values into Labels

LogicalNameColumn: lab_tradingregions
LogicalNameTable: contact
Conversion Type: Value to Label
Choice Label or Value: 2,3,4

And also Labels into Values:

LogicalNameColumn: lab_tradingregions
LogicalNameTable: contact
Conversion Type: Label to Value
Choice Label or Value: Africa; Asia; Caribbean; Central America; Europe; North America; Oceania; South America

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