cancel
Showing results for 
Search instead for 
Did you mean: 
annetoal

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!

 

About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/