Skip to main content

Notifications

How to Batch Notifications in Power Automate

How to Batch Notifications in Power Automate

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:

  1. Get all the files and metadata from the SharePoint library that have a valid approver email and are not folders.
  2. Sort the files by the approver email column.
  3. Extract the unique approver emails from the sorted files.
  4. Loop through the unique approver emails and filter the sorted files by each email.
  5. Pass the filtered files to the notification action of your choice.

Let’s see how each step works in detail.

Step 1: Get all the files and metadata from the SharePoint library

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:

annetoal_3-1701184946066.png

body('Get_files_(properties_only)')

Step 2: Sort the files by the approver email column

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:

annetoal_4-1701185117565.png

sort(variables('unsorted'),'approverEmail')

Step 3: Extract the unique approver emails from the sorted files

We use the Select action to create a new array that contains only the approver email column from the “sorted” array.

annetoal_5-1701185235882.png

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:

annetoal_6-1701185284137.png

union(body('Select_emails'),body('Select_emails'))

Step 4: Loop through the unique approver emails and filter the sorted files by each email

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.

annetoal_7-1701185417810.png

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.

Step 5: Pass the filtered files to the notification action of your choice

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!

 

Comments

*This post is locked for comments