Get Choice field Text in Power Automate from Microsoft DataVerse/CDS
Working with Power Automate is not new but sometimes the out-of-the-box value assignment is not sufficient to get correct data items so we need to tweak the expression to get the correct result.
In this post I will explain how you can get the choice field text value in power automate. let us say I want to get the Lead Source from Lead entity and store in a variable then If I will just assign the Lead Source value to the variable using Dynamic panel then it will just display the value for the choice field. As below screenshot it only displays the value.
The above flow will just assign the Lead Source Choice value field as 1. As you can see in the Run History.
But my intention is to assign text field of the Lead Source so for this we need to add some code in expression.
To identify what should you use to get the text field you have to check the output generated for the “Get Row By Id” step in run history. Go to run history and open the last run instance.
Now click on the step which retrieves the entity records for my case it is “Get a Row By Id”. Copy the Entire Body field and copy to a notepad of your choice.
Now there search your desired field for my case it is “leadsource”. You can see a section where your field is there in the notepad you can mark it that the leadsourcecode has two statements. one is for value and another is for text.
So to get the text e have to use the below expression format.
leadsourcecode@OData.Community.Display.V1.FormattedValue
Like that all choice field will have the same syntax. Now let us go and update our flow. Go to the step where you assign the field and use Peek Code to check the code generated.
The code will look like the below. For Lead Source the value property is assigned as below.
"value": "@{outputs('Get_a_row_by_ID')?['body/leadsourcecode']}"
Now we will copy the code for value and reframe using Formatted value syntax as below.
outputs('Get_a_row_by_ID')['body/leadsourcecode@OData.Community.Display.V1.FormattedValue']
Now go to flow and click Done to switch to Design mode and delete the value Lead Source assignment rather add our reformatted code as below using expression .
Now test this and check the variable value. Now you can see the Text value appears.
I hope this helps you.
Follow and subscribe my site and YouTube channel.