Send a Flow Approval to a SharePoint Group's Members - Perficient Blogs
Blog
  • Topics
  • Industries
  • Partners

Explore

Topics

Industries

Partners

Send a Flow Approval to a SharePoint Group’s Members

Out of the box Microsoft Flow does not currently support getting the members of a SharePoint group. This makes it difficult to utilize existing groups that outdated SharePoint Designer Workflows would use. This leaves two options for a flow creator, A) create a custom list to track approvers, or B) set static emails in the approval Flow itself. By using SharePoint groups instead, we can allow an end user to update this in the future, without having to touch the Flow.

Thankfully with the SharePoint API action available in Flow, we now have the ability to query SharePoint groups. This will return an array of objects containing the users information including the email.

Initial Flow Configuration

To properly configure the approval action we need to first initialize a string variable.

With the variable initialized, we can now call the HTTP Request action to pull the groups members.

Once you select the site, you can configure the Uri to call the group rest API (See Microsoft documentation for more details). If the name of the group can potentially change, you can also use the ID of the group instead by using the syntax: http://<site url>/_api/web/sitegroups(<group id>)/users

After the URI it is also important (and required) that you set the accept and content-type header properties to “application/json;odata=verbose”.

Iterate over the Response

The next step will be to now iterate over the results of this call. The response object that is returned will be in the following format:

{"d":{
"results":[{
"__metadata":{
"id":"http:///_api/Web/GetUserById(16)",
"uri":"http:///_api/Web/GetUserById(16)",
"type":"SP.User"
},
"Groups":{"__deferred":{"uri":"http:///_api/Web/GetUserById(16)/Groups"}},
"Id":16,
"IsHiddenInUI":false,
"LoginName":"i:0#.w|domain\\user1",
"Title":" User1 Display Name ",
"PrincipalType":1,
"Email":"user1@company.com",
"IsSiteAdmin":false,{
"__metadata":{
"type":"SP.UserIdInfo"},
"NameId":"s-0-0-00-000000-0000000000-0000000000-000000",
"NameIdIssuer":"issuer id"
}}, ...]
}}

Flow cannot auto detect the properties returned so we will need to manually enter the values using Workflow Expressions (see workflow definition documentation). In order to iterate over the results, create a for each loop and pass in the value body(‘name of HTTP Action in Flow‘)[‘d’][‘results’].

This will get us into the results array and allow us to reference the different properties (i.e. Email) of each member. Within the For Each loop, we will then create an Append to String Variable” Action.

Again since we do not have the properties auto populated, we will need to use workflow expressions. The value here follows the format items(name of For Each Loop’)[‘Email’].

NOTE: make sure to add a semi-colon after the email. This can either be done with expressions (using the concat function) or can simply just be added after the value (see screenshot above).

Once we are done iterating through the list, we can now configure the Approval action. This can be configured as needed, just make sure to set the Assigned to field to the emailList variable.

Once the approval is configured, you will just need to configure how to handle the approval response with a condition. Feel free to reach out (or leave a comment) if you have any questions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to the Weekly Blog Digest:

Sign Up