How to Query Dynamics 365 Multi Select Option Sets within Power Automate


Multi Select Option Sets within Microsoft Dynamics 365 are a great addition to the UI and user experience. However, from an admin / developers point of view we know that they can be painful to deal with.

In this post I hope to make your life a little easier by showing you how to get the selected text values from a Microsoft Dynamics 365 multi select option set using Power Automate (Flow) and also how check the field for a specific value using a condition control.

Overview

Within this example I’ll be using a new multi selection option set field which I’ve named Type (new_type) on the contact record. This field has the following options:

  • Type A
  • Type B
  • Type C
  • Type D

This flow will trigger on the contact type field being updated and will action logic only if the contact record has Type B selected within its list.

Example

The flow below uses Common Data Service (current environment) connector, the easiest way to create it is to create a new solution at https://make.powerapps.com/ then select “New | Flow”. From there:

  1. Select Common Data Service (current environment)
  2. Select When a record is created, updated or deleted trigger
  1. Set up the trigger to fire on a create or update of a contact record, and to fire the flow for all users (i.e. organization scope):
    • Trigger condition: Create or Update
    • The entity name: Contacts
    • Scope: Organization

Note: At the time of writing this post, multi select option set fields are not passed within the Common Data Service trigger. So in order to get the value of new_type we need to add a Common Data Service Get Record action.

  1. Add a Get Record step in order to get the new_type field’s value:
    • Click New Step
    • Choose the action Common Data Service | Get a record and set it up to do the following:
      • Entity name: Contacts
      • Item ID: Contact Id from the trigger step
      • Let’s also limit the get record action to just the field we are interested in:
        • Click Show advanced options
          • Set Select Query to new_type
      • Rename the step to GetContactType
  1. Next, we’ll unitize a Compose step to transform this data into a semi colon separated string:
    • Add a Compose Data Operation action
    • Set the Inputs field to the following expression (ensure Expression is selected):
      • Outputs(‘GetContact’)?[‘body/new_type@OData.Community.Display.V1.FormattedValue’]
    • Rename the step to ContactType

If the contact had Type D and Type B selected the output of the compose step will look something like this:

Type B; Type D

  1. The last step now is to check to see if the Contact Type field contains “Type B” within it’s values. We do this by using an Index function on the output of the Compose:
    • Add a Condition Control
    • Set the value to the following expression:
      • indexOf(outputs(‘ContactType’), ‘Type B’)
    • Set the operator to is not equal to
    • Set the value to -1

And that’s it, from there you can add your logic as required based on the answer of the condition check. If the mulit select string contains “Type B” then Index will return the starting index of the word, otherwise it it’s not found, it will return -1.

I hope I’ve saved you some time. Feel free to comment below if you have any questions.

One thought on “How to Query Dynamics 365 Multi Select Option Sets within Power Automate

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts