Often here on the forum someone asks how to send a notification based on a list/library grouping items instead of sending one email for each item, e.g. in a task list I want a single notification for each assignee with the list of all the tasks that are assigned to that specific people..
This is my solution, hope it can help someone!
First action will be a Query List Action where I can set all the optional filter, if I don't want to get all items in my source and, most important, I sort items by the field I want to group by.
Then I save all the fields I want to include in my notification in collection variable, also the field I want to group by should be stored in a collection variable.
Then I start looping on the groupBy collection variable and then I get all the related information from the other collection using the same index:
If the index is not equal to 0 and the previous value of my grouping condition is not equal to the current one, I'll send a notification with the previous built text and then I clear it and change the variable pPrevAssignee with the new grouping condition
Outside the Run If I'll update the variable with the text I want in my email
Last step, outside of the For Each, I have to send a notification to last assignee (I've that value inside my variable pPrevAssignee) otherwise last grouped items will not be notified.
And that's how my workflow looks like:
Edit 28/04/2017: I've added the workflow on Xchange Send Grouped Notification Site Workflow and I've moved the Set variable action outside the Run If (in the second screenshot of the workflow)