How to use SharePoint groups in your Power Automate flow

There is a team of engineers who are responsible for updating and maintaining documents stored in a SharePoint library. Everybody may read the documents, but a select group of engineers may actually edit them as well. In order for readers to be able to submit suggestions and other changes, we’ll make use of a SharePoint list with which everyone can submit a suggestion. A Power Automate flow will pick up on each new item and start an approval flow to process the submissions and keep the submitters informed during the process.

A team of engineers can be dynamic in terms that people come and go. The site owner regulates people flow with use of SharePoint groups. You’ll have you’re standard groups with their respective privileges:

  • Owners – Full control
  • Members - Contribute
  • Visitors – Read

In addition to these groups, I’ll add one more with its respective privilege:

  • Approvers – Approval

An approver is a role for approving submitted changes to the document library AND the submitted suggestions in the suggestion list.

With use of the SharePoint Approval group, Power Automate Flow, Power Automate Approval Action, SharePoint Web API and SharePoint http request Action, we can make a powerful flow with no fiddling from a user perspective.

What do you need:

• Microsoft 365 account with

  • E3 license or higher
  • Microsoft 365 Business Basic or higher
  • Equivalent non-profit license

• SharePoint Modern Site

  • No particular flavor

• Document Library

  • Title
  • Name

• Custom SharePoint list

  • Title
  • Item (lookup field to title field of Document Library)
  • Description (multi line, plain text)
  • Status (single line text)
  • Approver Responses (multi line, plain text)
  • Non are required fields

• Power Automate

Now to construct the flow

Geen alternatieve tekst opgegeven voor deze afbeelding

• Trigger action is SharePoint, When an item is created


• Create a string variable to store the approvers email addresses in


• Create a string variable to store the approvers comments in


• Create a string variable to store the approval process status in


• Create a SharePoint Update item action

• Update the item status of the suggestion to Pending


 

Now the hard part: Getting the e-mail addresses out of the SharePoint Approvers group.

In SharePoint, change the address after the site name and add /_api/Web/SiteGroups:

Geen alternatieve tekst opgegeven voor deze afbeelding

Scroll down until you find your approval group:

Geen alternatieve tekst opgegeven voor deze afbeelding

Next click on the users uri above the found group (see picture above)

Check if the users stated here conform with the users in the SharePoint approvers group! If so, copy the uri from the address bar of the browser. In my case:

Geen alternatieve tekst opgegeven voor deze afbeelding

Now to use this knowledge in the flow. Continue where you left of and make a new step:

Geen alternatieve tekst opgegeven voor deze afbeelding

• Create a SharePoint, Send an HTTP request to SharePoint action.

• Select the correct site

• Use the GET method

• Fill in the uri found for your approval users’ e-mail addresses

• Leave the rest blank

The output of this request will be the JSON code you saw earlier when clicking on the users uri. Next we need to process that code to something usable. Make a new step:

Geen alternatieve tekst opgegeven voor deze afbeelding

• Create a Data Operation, Parse JSON action

• Select the body content of the “Send an HTTP request to SharePoint”

• Use the below Schema*¹

Let’s store the e-mail addresses. Make a new step:

Geen alternatieve tekst opgegeven voor deze afbeelding

• Create a Variables, Append to string variable action

• Select the varApprovers variable to append to

• Click Value and select the Parse JSON output for Email from the Dynamic content tab

Once you click the Parse JSON Email value, your Append to string variable action will be put in a Control, for each action. This is because there could be multiple email address that all must be appended to the variable.

Don’t forget to add the semi column ( ; ) behind Email.

Geen alternatieve tekst opgegeven voor deze afbeelding

Now it is time to start the approval process. Make a new step.

Geen alternatieve tekst opgegeven voor deze afbeelding

• Create an Approvals, Start and wait for an approval action

• Pick an approval type that best suits your situation

• Create a title that makes some sense

And next we’ll make use of our Approvers SharePoint group!

• Assign to the varApprovers variable.

• Put the suggestion description body in the Details field

• Item link, link to suggestion

• Item Link description, Title of the suggestion

We’re almost done, Hang in there!

The Approval process will generate some output. For one, the approver will Approve or Reject the suggestion and there will be some kind of response for what reason the suggestion is approved or rejected upon. This is valuable information for the user who made the suggestion in the first place. Make a New step.

Geen alternatieve tekst opgegeven voor deze afbeelding

• Create a Data Operations, Parse JSON Action

• Select the Responses body of the Start and wait for an approval output

• Use the below Schema*²

 Now we’re going to pick the comments from the JSON and append it in our varResponses variable. Make a New step

Geen alternatieve tekst opgegeven voor deze afbeelding

• Create a Variables, Append to string variable action

• Select the varResponses variable

• Click Value and select the Parse JSON output of Start and wait for an approval from the Dynamic content tab

Once you click the Parse JSON Comments value, your Append to string variable action will be put in a Control, for each action. This is because there could be multiple comments that all must be appended to the variable.

Don’t forget to add the semi column ( ; ) behind Comments

Geen alternatieve tekst opgegeven voor deze afbeelding

The last two pieces will update the status of the suggestion, add the approver comments and send a closing notification to the user who made the suggestion.

The outcome of an approval is either Approved or Rejected, so we’ll need a condition to get things going in the right direction. Make a New step.

Geen alternatieve tekst opgegeven voor deze afbeelding

• Create a new Control, Condition action

• Set the condition to Outcome of the Approval is equal to Reject

 If the outcome of the condition is true:

Geen alternatieve tekst opgegeven voor deze afbeelding

• Create a SharePoint, Update item action

• Update the Status to Approved

• Select varResponses for the Approver Responses field


• Create a Variables, Append to string variable action

• Select varStatus

• Select Status of Update Item action mentioned above

If the outcome of the condition is false:

Geen alternatieve tekst opgegeven voor deze afbeelding

• Create a new Control, Condition action

• Set the condition to Outcome of the Approval is equal to Reject

• Create a SharePoint, Update item action

• Update the Status to Rejected

• Select varResponses for the Approver Responses field

• Create a Variables, Append to string variable action

• Select varStatus Select Status of Update Item action mentioned above

And lastly, lets notify the submitter of the outcome of its suggestion:

Geen alternatieve tekst opgegeven voor deze afbeelding

• Create a Mail, Send an email notification

• To: Created by Email (from the “When an item is created part” from the start of this flow)

• Create a pretty subject

• And fill the body appropriately mentioning the actual suggestion, its outcome and the comments of the approver

And you’re done! Of course, I haven’t mentioned the approval itself. but, that is for another day 😊

Until next time, stay healthy!

Ramon Hublart

Geen alternatieve tekst opgegeven voor deze afbeelding


               


Schema*¹

{
    "type": "object",
    "properties": {
        "d": {
            "type": "object",
            "properties": {
                "results": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "Email": {
                                "type": "string"
                            }
                        },
                        "required": [
                            "Email"
                        ]
                    }
                }
            }
        }
    }
}

Schema*²

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "responder": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "displayName": {
                        "type": "string"
                    },
                    "email": {
                        "type": "string"
                    },
                    "tenantId": {
                        "type": "string"
                    },
                    "userPrincipalName": {
                        "type": "string"
                    }
                }
            },
            "requestDate": {
                "type": "string"
            },
            "responseDate": {
                "type": "string"
            },
            "approverResponse": {
                "type": "string"
            },
            "comments": {
                "type": "string"
            }
        },
        "required": [
            "responder",
            "requestDate",
            "responseDate",
            "approverResponse",
            "comments"
        ]
    }
}

Comments