Power Automate | Get Option Set Text with Child Flow

Microsoft is encouraging the replacement of traditional workflow processes with Power Automate (formerly Microsoft Flow). And with that change, there are certain times where flows handle items 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 Option Set, in particular, the text. Many times, the text of the Option Set is needed in addition to the value, but, in flows, only the value is available. For example, if we wanted to send an email to a customer and place dynamic values in the body of the email, the Option Set text is not readily available. We need a reusable method to retrieve the Option Set text. Let’s figure it out together.

Situation

You need to use a selected option set text in your flow instead of the selected option set value. You would like to create a flow component which you can reuse for other flows.

For this particular example, I needed to display an option set text in an email instead of the option set numeric value, as these emails will be sent to customers and the numeric value would have no meaning. I knew I could use a switch control, but I also knew I would need this same methodology across several flows, and I didn’t want to recreate it more than once.

Solution

I created a black-box flow control that would receive a numeric value (option set value) and return the matching option set text to be used throughout the calling parent flow.

Important

Flows must be created within the D365 (Dynamics 365) solution OR outside the D365 solution for them to communicate with each other. I tested this by creating one black-box flow inside the D365 solution and one black-box flow outside the D365 solution, directly from flow.microsoft.com, and the D365 solution parent flow only had visibility to the D365 solution black-box flow.

As a side note, flows must be created within the D365 solution AND choosing the Common Data Service (Current Environment) trigger if you are creating a D365 email activity record. Only through this route will the Activity Party fields display.

Create Child Flow

Summary

The child flow is a HTTP request and response; it is similar in behavior to a JavaScript function that returns a value. The flow is called, possibly receives some parameters, does some work, and possibly returns a value.

Here is the overview of all the child flow steps:

Option-Set-Text

Create Power Automate Flow

For this particular example because the child flow is working with a parent flow that needs to create and send a D365 email, it will be created inside the D365 solution.

Navigate to make.powerapps.com, login, navigate to the correct solution, and create a new flow.

Option-Set-Text

Choose When an HTTP Request is Received

Search for “request” to limit the possible flow triggers. Select “When an HTTP request is received.”

Option-Set-Text

Enter JSON Payload

The first step identifies the type of request and the type of data that will be received as parameters.

Because we are only working with D365 option set values as the incoming parameter, the JSON is quite simple. If needed, navigate to the appropriate option set definition and pull one of the values for the payload.

For this example, I entered:

{

“LicenceStatusReason”: 866980000

}

Option-Set-Text

*IMPORTANT – Do not identify the method or relativePath. Identifying the method as either “GET” or “POST” causes errors.

Option-Set-Text

Initialize Variable

You need to store the child flow value somewhere so search for “initialize a variable”, give it a name, and set the Type equal to String.

Option-Set-Text

Switch Control and Set Variable

Here comes the tedious part, depending on the number of option set values available. But remember, you can reuse this flow across the rest of your flows created inside the D365 solution.

Option-Set-Text

Add new step, search for “switch,” and then set the “Equals” value to the D365 option set value. Add new step, search for “set variable,” select correct variable for Name and enter D365 option set text or what you would like to display instead of the option set value.

Option-Set-Text

Send Response

Now that we have processed the incoming parameter, we need to send back the response, or return a value.

Add new step, search for “respond to a powerapp or flow,” select “Text,” enter a name for the outgoing response, and select the set variable flow item for the value.

Option-Set-Text

We have completed our child flow. Congratulations!

Create Parent Flow

Summary

The parent flow will initialize a variable, call the child flow, set the variable with its response, and then use it further down in the flow.

Below is a screenshot of the entire flow, but we’ll only focus on the handling of the child flow results.

Option-Set-Text

Choose Trigger

For this example, I selected “When a record is created, updated, or deleted” as the trigger for the parent flow. I set the entity name, scope, and identified the D365 logical name values of the fields that will trigger this flow on update.

Option-Set-Text

Initialize Variable

We need to store the response value into a variable. Add new step, search for “initialize variable,” enter a name, and set Type to String.

Option-Set-Text

Before calling the child flow which only works with a JSON object and not D365 fields, we need to add a condition to see if any Option Set value exists. It is simpler to work with nulls on the D365 parent flow side of things.

Option-Set-Text

First, we determine if the D365 Option Set has any value by comparing the field value to the null object expression. In the yes result, we call the child flow and set the Licence Status Reason variable with its response. In the no result, we set a default value to the Licence Status Reason variable.

Call Child Flow

Now let’s cover the call to the child flow. Add new step, search for “run a child flow,” select Child Flow name, and set the parameter (the option set value of the record being created or updated).

Option-Set-Text

Set Variable

Add new step, search for “set variable,” select the correct variable, and set the child flow result to Value.

Option-Set-Text

Use Response

Now we are ready to use that response value in the rest of our parent flow. In this case, I am building the body of an email record. Wherever you need the child flow response value, click inside the field and then choose the variable.

Option-Set-Text

Conclusion

When the flow is run, either a record is created or updated, a D365 email record is created, displaying the option set text value.

Option-Set-Text

If you’d like to learn more about using Power Automate in Dynamics 365, 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