Populate Activity Party Value with JSON Array in Power Automate

In this post, I will explain how you can dynamically populate the Activity Parties or any other array input parameter by switching to input entire array and populating with the JSON array.

In cloud flow, when the input parameter of the action is an array data type, the flow designer shows the input parameter in two different modes:
  1. Detail inputs for array item - allows the user to enter the input parameter for each item and add more items by clicking on "+ Add new item"
  2. Input entire array - allows the user to enter the JSON array of all items
You can toggle between these two modes by clicking on the icon at the top-right corner of the input parameter.

🔗 Detail inputs for array item

In the first mode, you can enter the properties of the object in each input field which is easier and more citizen developer-friendly approach (no JSON knowledge is required). This option is suitable if the number of items is static and not going to change depending on the input data. For each additional item, you can click on "+ Add new item" which will show a new set of properties for an object.
In this second mode, you need to enter the whole data as a JSON array in the input textbox as one big chuck of text. This option is suitable if you want to add the items dynamically (e.g. send email to all contacts of an account in one single email) or set the property of an object which is not available in the detail inputs view (e.g. send email to unresolved recipients with "addressused" column).

In the sample cloud flow below, this creates an email and populates the To Recipient with multiple Contacts from the List Record action output.


1. Initialise Array Variable
First, initialise an array variable and set the static values for the activity party array JSON. In this case, the email sender queue is a static value and the queue GUID with ParticipationTypeMask = 1 for Sender activity party type (check out Microsoft Docs for complete list) are added to the variable.

2. Append to Array Variable
Next, append each Contact GUID from the "List record" action output into the array variable with ParticipationTypeMask = 2 for To Recipient activity party type.

3. Create Email with JSON Array
Finally, populate the JSON array variable to the Activity Parties input parameter by switching to input entire array.

4. Send out the Email from the system
Follow the last step in this blog post to send out the email automatically from the flow using "Perform a bound action" step with "SendEmail" Action.



Not only for Activity Parties, but this approach can also be done for any other parameters which accept JSON array object (allow switching to input entire array). In the sample cloud flow below, multiple users are added to the team with a single AddMembersTeam bound action step which accepts Members parameter as JSON array. As similar to the flow above, we can dynamically add the team members by appending the User GUID to the array variable and set it as the Members parameter.

Summary

In cloud flows, you can dynamically populate the Activity Parties or any other array input parameter by switching to input entire array and populating it with the JSON array variable. You can then append data/parameters from other actions within the flow.

Comments

  1. Great work on the dynamic json values for multiple recipients, but how are you sending the final email? Is the final send automated or is it depending on a user to send it?

    ReplyDelete
    Replies
    1. You can send out the email automatically from the flow using "Perform a bound action" step with "SendEmail" Action as specified in this blog post.
      https://linnzawwin.blogspot.com/2020/05/send-email-from-dynamics-365cds-with.html#SendEmail

      Delete
  2. First of all this is VERY USEFUL. I was banging around trying to do it by building a JSON string.

    My question is about the FROM party. Does it need to be a queue? In my testing, if I set that to the queue associated with our sender (i.e. the queue for that systemuser), I get an error saying that it doesn't recognize that user. If I set the from as a systemuser(guid) it seems to accept it. Which is correct, or what are the caveats, please?

    ReplyDelete

Post a Comment

Popular Posts