Skip to main content

Notifications

Update Multi-Values with People Picker Field in Power Automate/Microsoft Flow

Introduction 

In this article, we will learn how to update multi-values with the people picker field in Power Automate or MS flow. Updating a multi-value people picker field in MS flow or power automate is a little tricky, and recently a friend came to me for help on this. After lots of trial and error, I was finally able to manage to update the multi-value people picker field. Let us see how to achieve this.
Objectives
  • Find an Office 365 group ID associated with site
  • Find a list of all members of this office 365 group
  • Add these members to a list column (people picker with multi-value) 
Let's start by building our flow.
 
For demo purposes, we will use manual trigger action.
 
Step 1
Add "Manually trigger a flow"  as a trigger point.
Step 2 
Add Initialize a Variable action, select type as Array
 
1.png
 
Step 3
 
The next thing we have to do is get the Office 365 group ID associated with the site.
 
To get a group ID of the site, we can use the endpoint '_api/site/',  which has GroupId as properties, this is the GroupID of the Office 365 group.
 
Add the action, "Send an HTTP request to SharePoint", and select parameters as below. 
 
Though I have selected the site address directly from the dropdown, you can always use dynamic content or expression (if you are getting the site URL from somewhere else) 
in Uri, I am directly using _api/site/GroupId so that I don't get any other site properties (which I don't require in this case).
 
Step 4
 
The next thing we will do is use Parse JSON action so that the response of the above action can be directly used in the next steps from a dynamic content window.
 
Use below sample JSON as payload in 'Use sample payload to generate schema'.
 
{
"d": {
"GroupId": "8db58c1c-22-232-adde-2332"
}
}

 

2.png

 

Step 5
 
Now that we have GroupId of office 365 group, we will query group members by using the action 'List group members'.
 
3.png
 
Step 6
 
The above action will return an array of group members so we will have to loop through each member and generate the required array to pass to people picker column.
 
Add 'Apply to each' action, select an output of above action in 'Select an output from previous step'
 
Step 7 
 
Add a compose action and the below JSON string, you can always replace  @{items('Apply_to_each')?['mail']} by selecting dynamic content mail property from 'List group members'. As you can see in the screenshot below, (with marked as 7), I have used a dynamic content selector to add mail property. 
 
{
"Claims": "i:0#.f|membership|@{items('Apply_to_each')?['mail']}",
"Email": "@{items('Apply_to_each')?['mail']}"
}

 

Step 8 
 
Append this compose method output to Array. Select 'Append to Array variable' action and select Managers as the Name, and 'output' as the value.
 
4.png
 
Step 9 
 
Now we have the required object to update the people and group column. Now let's use the create item action and select values accordingly.
 
For the Managers column, (which is people picker with multi-value allowed), click on the icon marked with a green arrow in the below screenshot. This will switch to input for th entire array. Select the Mangers variable here. 
 
5.png
 
Save workflow and test it. If everything goes well, it should run successfully.
 
6.png
 
Let's check in the list item.
 
7.png
 
We should see that multiple users are updated in the Manager field. 
 
Conclusion
 
Updating the people picker column with dynamic values is a little tricky. This article will give you the basic idea of how to form JSON which is required to update the PeoplePicker column if our user's value is not coming directly from SharePoint. 
 
Hope you enjoyed reading...Happy flowing..!!!
 
P.S - This article was originally published at this link

Comments

*This post is locked for comments

  • guilefox Profile Picture guilefox 4
    Posted at
    Update Multi-Values with People Picker Field in Power Automate/Microsoft Flow

    When I tried to recreate this GroupId is returned as 00000000-0000-0000-0000-000000000000?

     

    So it fails at the "List the Group Members".

     

    In step 3 do you leave the Body blank?

    And in step 4 you click "user sample to generate schema" and paste in the below JSON?

     

    {
    "d": {
    "GroupId": "Office 365 ID"
    }
    }

     

    Also I was wondering why do I need to do these steps, why can I not just put in the specific "group ID" into the "List Group Members action"

  • OliverR-82 Profile Picture OliverR-82 615
    Posted at
    Update Multi-Values with People Picker Field in Power Automate/Microsoft Flow

    Hi @siddharth_v ,

    Thank you for taking the time to write this post. I'm trying to accomplish something similar to what you describe here, but instead of an O365 Group I need to assign a SharePoint List item to members of a SharePoint Group. I can get the users of the SP Group fine via an API call, but I get the following error on the For Each action:

     

     

    The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@outputs('GetSPGroupUsers')?['body']' is of type 'Object'. The result must be a valid array.

     

    My flow looks like this:

    OliverR-82_0-1609759611684.png

    I suspect that I need to use a different output in my Apply to Each action (currently it is the 'body' of GetSPGroupUsers), but I don't know what or how to get it. I retrieve the users from the SP Group by calling the API as follows:

    OliverR-82_1-1609759712643.png

    That works fine, it gets me the expected output.

    Can you tell me what I am doing wrong?