Have you ever been tasked with building an integration between Microsoft Dynamics 365 and an external system that does not have an out of the box connector? Have you ever run into an issue where you need to populate option sets in Dynamics 365 but all you have are the option labels? Have you ever started to write a massive switch statement into Microsoft Power Automate to map that option set and question what you were even doing? Then you are in the right place, because you can do that mapping automatically and futureproof against changes to the option set in Dynamics 365 all at the same time.
As an example, let us say we need to populate the “Preferred Method of Contact” field on a Contact, but can only get values like “Phone” or “Email” from the source system. No problem, just start by making a new flow with “When Power Apps calls a flow” as the trigger. The trigger will need three inputs: the name of the entity you are targeting, the field you are targeting, and the label of the option set value you are looking for. The trigger should look like the following when you’re done getting set up.

The node that is going to do most of the heavy lifting for this flow is going to be an “Invoke an HTTP request” node. I used the HTTP with Microsoft Entra ID HTTP request for this example, so once you get the authentication set up, you will need the following information to make the request:
Method: GET
Url of the request: https://<your D365 environment URL>/api/data/v9.2/EntityDefinitions(LogicalName='<entityName>')/Attributes(LogicalName='<fieldName’>')/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet($select=Options)
This call will return all option set labels and values for the provided field on the provided entity. Once we have that array of values, we can parse the returned JSON and filter it using the option label passed into the flow.


After you have filtered the results down to a single result, you can put a “Respond to a Power App or flow” node at the end of the flow, make an output parameter, and set it to the “Value” property of the first item in the filter array node.

With the flow complete, you can now call this flow from others using the “Run a Child Flow” node within your integration flow. All you need to do is pass in the entity, field, and option label to the flow and it will return the option set value for you to use to update the option set in Dynamics 365.

As a final debugging note, you may run into an error when saving a flow that calls the option set flow that mentions “run-only users”. This is caused by Microsoft Power Automate losing context for what connection to use when calling a child flow, even if there is only one connection specified in the child flow. To fix this, there is a section on each flow’s page called “Run-only user” where you can explicitly address what connections you want the flow to use. Once this has been updated, you will be able to save the flow that is calling the option set flow and it should run properly.

With that, you should never have to deal with issues like writing switch statements to handle option sets or worry about users adding in a new option set value and how that will impact existing Microsoft Power Automate integrations.
Joshua Kranhold – Senior Consultant
Working with New Dynamic
New Dynamic is a Microsoft Solutions Partner focused on the Dynamics 365 Customer Engagement and Power Platforms. Our team of dedicated professionals strives to provide first-class experiences incorporating integrity, teamwork, and a relentless commitment to our client’s success.
Contact Us today to transform your sales productivity and customer buying experiences.