Use Flow To Update A Multi-Select Option Set
by Adam P, Endeavour Solutions. (You may also like our article on Dynamics 365 Virtual Agents / Chat Bot)
I was daydreaming a few days ago about Flow and how it could do so much more than out of the box classic Dynamics workflows. It got me thinking about some common issues we face with workflows and how we usually have to get creative to solve these gotchas. So, I asked myself “can Flow handle something like Multi-select option sets?”. I set out to find out if it worked, and guess what? It does, and it works great. Read on to find out how I did it.
In 2018 Microsoft launched a great new feature as part of Dynamics 365 v9, the Multi-Select Option Set. This had been a long-awaited request by the user community to save a lot of customers the headache of building workarounds. However, whilst it answered some prayers, it was not fully-fledged and had its limitations, primarily around interacting with the field via workflows. Let’s look at a simple example.
I have multiple product lines and I want to use a multi-select option set to capture what products the customer is interested in. Are they interested in the Apple Watch and the iPhone, for example? So I want a workflow to compare the values selected in the Multi-select Option Set and do something if my condition is met or not. Sounds simple, let’s dig in.
So we open our old workflow engine in D365 and set a condition for when our multi-select option-set equals Apple Watches….
…the multi-select option set field is not available in the condition, it simply is not available to pick. Neither can we update it on the form.
Traditionally we would look for a workaround using standard option sets or lookups or start building a plugin to handle the requirement etc. Untidy and cumbersome for what should be a simple request. Multi-select ,therefore, gets a bad rap and are not as popular as they should be.
I have been using flow A LOT recently and I love it, it is a game-changer for anyone who is not adept writing C# or who wants a solution that the customer can look after moving forward with more transparency (in fact, for these reasons and its feature set, I think it can be a replacement in many cases for plugin code).
I was day-dreaming one day and got thinking, “Flow can do a lot that workflow can’t. Can it handle Multi-select Option Sets?”
So, I got to work and ran a test and guess what? It works. Yes, that’s right folks, you can run conditions and update a multi-select field in Dynamics 365/Common Data Service using Flow and here is how.
Start by creating your multi-select field.
Then set up a simple Flow with a Dynamics 365 trigger (could also be a CDS trigger), it can be on the record created or record updated, up to you and doesn’t matter. Then add a Compose action and set the value as your Multi-select Option set field, we will use this Compose later. In my example there were two fields, one called “Test Multi-select” and “Test Multiselect Label”, do not use the value “Test multiselect label”. Using values means if you want to change the label you are free to without needing to update the flow (Also I couldn’t get it to work using Label, it didn’t bring back any values).
Run a quick test to see that you bring back some values, you will notice that it brings back an array separated by a comma. Nice.
“Tip: Use this test moving forward as your trigger so you don’t need to go back to D365 and keep updating the record. Stay in Flow from now on whilst testing. Simple.”
Add a new compose action and put in the value we are comparing against. in my case 859270000 which is the Item I want to send an email for, this is “Compose 4” in my demo.
Set up your condition. Choose “Condition” as your action.
In the first box put the value returned from our trigger, in my case “Compose”. Next, the operator should be “Contains” for obvious reasons (it will never equal if more than one) and in the right box put our new compose value from Step 3. We do this so that they are both the same “type” otherwise one is an integer and one a string and you will get errors. this avoids that. You could use an expression to transform your inputs but I find this way simpler and more transparent when scanning.
Add your steps if your condition is met or not. For this demo I have shown that you can update the Multi-select field on a Dynamics 365 record with your new value. You need to mindful of the existing fields already so use your initial”Compose” and using Concat() expression join your two Composes used earlier. like so:
Test it and see that it works, beautiful.
Your flow ran successfully
This is just a small example but using the power of Flow you can now do all sorts with your Multi-Select field such as send emails, update another record etc.
Pretty cool, eh?