Thursday, July 9, 2020

Set Optionset label in Power Automate CDS Dynamics 365 Cloud Flows

Set Optionset label using Power Automate CDS Dynamics 365 Cloud Flows

Here in this blog, I will show a sample process to set optionset labels using Dynamics 365 power automate MS Flow.

How to retrieve option set labels via the CDS connectors and How to set it to the Email body?

Please follow the sample process step by step:

In this blog, I'm using Common Data Service(Current Environment) Connecter to achieve the requirement.

There are two ways to set the labels, you use either of it to achieve your goal.
--------------------------------------------------------------------------------------------
Process 1. This is the simplest way to set optionset label:

Step1: I'm triggering the flow when a new lead is getting created.
           
           

Step2: Initialize variable:

             

Step3: Set Variable: Use previous triggered output
               

Note: query triggereOutputs from step 1, as shown
         

You can use the same set variable (strLeadSourceCode) and set wherever you want to set it, in my case I'm setting it in the email body. That's it!
--------------------------------------------------------------------------------------------------

Process 2. This is the Complex way to set optionset label:

Query String Maps table
The String Maps table is the table that contains the metadata behind your optionsets and it can also be queried via a List records action.

Step1: First initialize a variable of type array to store the result of our "List records" action.

Step2: List Records from String Maps table as shown below:

Then query the stringmap table for all values of the relationship type optionset by providing the entity (=objecttypecode) and the field (= attributename) in the filter:


Step 3 and Step 4:
As shown below -> Inside Apply to each7 loop
a) Compose and add inputs 
b) Append to array variable2 which created in the previous step1 and value Outputs is from compose.

As an in this step I loop over all results and append them to our array variable, to have a dictionary to lookup the optionset labels based on the values:


Step5: Again List All the Lead Records as shown

Perform a "List records" action to query all Lead


Step6 and Step7: Again Inside Apply to each8 loop add 
a) Filter Array with the condition to filter the label which you selected on the record form
b) Compose2 to get the actual output body

Loop over all returned leads and filter the array based on leadsource:

Finally, access the optionset labels via the following formula as shown in compose:




This is the final output of above


Result: Finally see the result below:


Step8: Use this leadsourcecode_label value and you can initialize one more extra string variable and assign the leadsourcecode_label outputs and use it on the email body as in my case.


Run result:

Use this strLeadSourceCode variable on wherever you want to set.

That's all! Thanks...