Power Automate | Get Choice Label From Metadata

Microsoft is encouraging the replacement of traditional workflow processes with Power Automate (formerly called Microsoft Flow). And with that change, there are certain items where flows handle things differently, and we, as developers, need to find the best methods to develop solutions that contain flows.

This blog will surface a way that flows can expose the Choice column, in particular, the label. Many times, the label of the Choice is needed in addition to the value, but, in flows, the label is somewhat hidden and below the surface. For example, if we wanted to send an email to a customer and place dynamic values in the body of the email, the Choice label is not readily available. We need to expose the metadata of the Choice column to use throughout the flow. Let’s figure it out together.

Situation

You need to use a selected Choice label in your flow instead of the selected Choice value.

For this example, I needed to display a selected Choice label in an email instead of the Choice numeric value as these emails will be sent to customers and the numeric value would have no meaning.

Solution

The column in question is Industry on the Lead table. We can see from the below image, that it is a Choice column:

Power-Automate-Choice

On the Lead form:

Power-Automate-Choice

Create Flow

Summary

Here is a summary of the entire flow:

Power-Automate-Choice

Create Solution

Navigate to the desired environment and create or find the solution. Here, I created the following solution:

Power-Automate-Choice

Create Power Automate

From inside the solution, click New and then Cloud flow:

Power-Automate-Choice

Choose Trigger

When the flow opens, select “When a row is added, modified, or deleted” as the trigger. Set the change type, table name, and scope.

Power-Automate-Choice Power-Automate-Choice

I always like to save my flow as soon as possible, so I add a Compose action, enter the Name field into the Input value, provide my flow a name, and save.

Power-Automate-Choice

Initialize Variable

We need to store the Choice label into a variable. Add new step, search for “initialize variable,” enter a name, set Type to String, and set value to null by using an expression.

Power-Automate-Choice Power-Automate-Choice

We will set this value after we retrieve the table data and metadata; let’s do that.

Get Lead

Right after the trigger, click the + Insert a new step action and search for Get a row by id. Select Leads for Table name and enter the Lead Id by using the expression.

Power-Automate-Choice

When completed, it should look like this:

Power-Automate-Choice

The order of flow components is now:

Power-Automate-Choice

Get Lead Metadata

Now to see what information we need to retrieve for the Industry Choice label, save the flow, and create a Lead, ensuring to enter a value for Industry.

Power-Automate-Choice

Navigate to the flow run:

Power-Automate-Choice

And view the results:

Power-Automate-Choice

Expand the Get Lead action results and scroll down to the body section.

I usually copy all the contents in the body and paste into Notepad++ so I can view the information easier.

Search for “industry” and you will find something like this:

Power-Automate-Choice

Set aside for now.

Set Variable

Edit the flow and add new step right after Initialize Industry action. Search for Set variable. Select the correct variable. Click in the value area and select Industry from the Get Lead dynamic content. It should look like this:

Power-Automate-Choice

Here comes the fun part. Select the contents of the above value and paste into Notepad. It will look like this:

Power-Automate-Choice

Remove the @ and the {}.

Navigate back to the Notepad++ where the Lead metadata resides from the previous run and grab the highlighted part of the following:

Power-Automate-Choice

Paste right after industrycode, and the result will look like this:

Power-Automate-Choice

Copy the whole thing, navigate back to the flow, remove the Industry you entered, click inside the value area, click the Expressions tab, paste the contents, and click OK.

Power-Automate-Choice

The result will look like this:

Power-Automate-Choice

Test

Since the flow has already run, we can test our new changes with previous data. Click Test at the top right, select Automatically, select a previous run, and click Save and Test.

Power-Automate-Choice

We can see that the set variable worked perfectly:

Power-Automate-Choice

Send Email

We have everything in place to build out our email body. After the Set Industry action, click New Step, search for Send an email (V2), select it, and fill out the required fields.

In the body of the email, we can enter the Industry variable result like this:

Power-Automate-Choice

Click in the email body where you would like the value, ensure the dynamic content dialog box is open and search for Industry, and select it.

Final Test

Click Test at the top right, select Automatically, select With a recently used trigger, select the last run, and click Save and Test.

The flow has successfully run:

Power-Automate-Choice

The email sent with the Choice label:

Power-Automate-Choice

We have learned a nice feature of the table metadata and that we can use in our flows. This same concept will work for Two Options, Lookups, and more.

If you have any questions about Power Automate, please connect with us.

Dynamics 365 CE (CRM) How-To eGuide

41 pages of step-by-step instructions for 6 different key tasks in Dynamics 365 Customer Engagement (CRM). Includes interactions with PowerApps and Flow!

Get the eGuide

Dynamics 365 CE (CRM) How-To eGuide

Get the eGuide