Some of the common operations / decision making one wants to perform in terms of programming is definitely switch-case!
Here’s how you can do it in power automate
Scenario
To keep things simple, I will simply reflect the name of the OptionSet value in a variable in Flow –
-
- Here’s my OptionSet called Account Type with values Customer [1], Vendor [2] & Partner [3]
- Here’s my OptionSet called Account Type with values Customer [1], Vendor [2] & Partner [3]
-
- My Flow will be called on update of Account record’s Account Type field change
- My Flow will be called on update of Account record’s Account Type field change
-
- I’m simply using a variable to store the value of the selection made on the field.
- I’m simply using a variable to store the value of the selection made on the field.
Using Switch
Now, let’s get to the important part –
-
- If you search for Switch under Control, you’ll see as below
- If you search for Switch under Control, you’ll see as below
-
- This will first ask you what the Switch should be on, in this case, it’s the Account Type value to be selected from the dynamics values
- This will first ask you what the Switch should be on, in this case, it’s the Account Type value to be selected from the dynamics values
-
- Now, I can start entering the Cases one by one as shown below and setting the variable I created above. For value in Equals 1, I’ll set variable as Customer
Clicking on the + [Plus] sign in between Case and Default will let you add more cases.
- Now, I can start entering the Cases one by one as shown below and setting the variable I created above. For value in Equals 1, I’ll set variable as Customer
-
- Finally, once all the cases are entered, the Flow will start looking something like this from a hawk-eye-view with the Default case appearing in the end.
- Finally, once all the cases are entered, the Flow will start looking something like this from a hawk-eye-view with the Default case appearing in the end.
Working
Let’s look at how Switch-Case would work –
-
- I updated the Account Type field with Vendor
- I updated the Account Type field with Vendor
-
- Switch on the Account Type Value (selected from Dynamic Values) will reflect the value of 2
- Switch on the Account Type Value (selected from Dynamic Values) will reflect the value of 2
-
- And Case 2 will execute simply reflecting what is stored in the variable. Rest of the cases will not run
- And Case 2 will execute simply reflecting what is stored in the variable. Rest of the cases will not run
Pretty Easy! Hope this helps!