If you use Power Automate to send notifications to reviewers of SharePoint files, you might have encountered a problem: how to avoid sending too many emails (or Teams messages) to the same person who has multiple files to review. In this blog post, I will show you how I solved this problem with the help of the Power Automate Community.
The goal is to group all the files that belong to the same reviewer and send them in one message, instead of sending one message per file. To achieve this, we need to do the following steps:
Let’s see how each step works in detail.
We use the Get files (properties only) action to get all the files and metadata from the SharePoint library. To filter out the files that do not have a valid approver email or are folders, we use an ODATA filter in the action:
(approverEmail ne null) and (ContentType ne 'Folder')
This will return an array of files and metadata that match the filter criteria. We store this array in a variable called “unsorted” using the Initialize variable action:
body('Get_files_(properties_only)')
We use the sort expression to sort the “unsorted” array by the “approverEmail” column. This will return a new array of files and metadata that are ordered by the approver email. We store this array in a variable called “sorted” using the Initialize variable action:
sort(variables('unsorted'),'approverEmail')
We use the Select action to create a new array that contains only the approver email column from the “sorted” array.
We have assigned the word “Reviewer” as the key for the new array, and the expression
item()?['approverEmail']
as the value. This will return an array of key-value pairs where the key is “Reviewer” and the value is the approver email.
We then use the union expression to get an array of all the unique values of the “Reviewer” key.
This will return an array of unique approver emails. We store this array in a variable called “uniqueEmails” using the Initialize variable action:
union(body('Select_emails'),body('Select_emails'))
We use the Apply to each action to loop through the “uniqueEmails” array.
For each email in the array, we use the Filter array action to filter the “sorted” array by the email.
We use the expression
item()?['approverEmail']
to get the approver email from the “sorted” array, and the expression
items('applyEach')?['Reviewer']
to get the email from the “uniqueEmails” array. We use the condition is equal to to compare the two emails. This will return an array of files and metadata that belong to the same reviewer.
We use the Create HTML table action to convert the filtered array into an HTML table that contains the file names and other relevant information.
We then use the Send an email action to send the HTML table to the reviewer. You can customize the email subject and body as you like. You can also use other notification actions such as Post a message as the Flow bot to a user or Send a push notification instead of sending an email.
That’s it! You have successfully batched notifications in Power Automate. You can test your flow by adding some files to your SharePoint library and assigning different approver emails to them. You should receive one notification per reviewer with all the files they need to review.
I hope you found this blog post helpful. If you have any questions or feedback, please leave a comment below or reach out to me on the Power Automate Community. Happy automating!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.