Intermediate | Flow of the week: Approval reminders using parallel branches
A common requirement from our customers is to send periodic reminder emails to approvers about pending requests. This post will show how to achieve this using Flow parallel branches. For those unfamiliar with parallel branches, they are a built-in mechanism for a Flow to perform multiple actions simultaneously. (For readers with programming experience, they are analogous to multi-threaded programming). We'll use one branch to perform the "Start an approval action", and another branch to wait for the approval to complete, and periodically send emails.
For our scenario, I'll have a set of approvers that need to acknowledge via Flow approval when files are added to a document library. After adding the "When a file is created (properties only)" trigger, I'll add two "Initialize variable" actions. One will initialize a boolean
approvalDone variable to false, and the other will set up my list of approvers. I'll explain why I need these two variables in more detail a bit later in the post.
Next I'll add the "Start an approval action" and hook up the inputs. I'll take the list of approvers from my variable, and reference the link to the file that was just uploaded.
Now that I have the approval action card configured, I need to set up the parallel branch -- the actions I want to happen while the approval is in progress. I'll hover the mouse ABOVE the "Start an approval card" and click the + sign, find "Add a parallel branch", and select "Add an action".
The Flow designer will now fork the execution arrow into two branches, placing the approval card on the left and bringing up the connector/action dialog on the right. This is to help us visualize that both forks will execute simultaneously.
Before we can start adding the reminder logic on the right side of the fork, I need to add one more action on the left after the approval. Remember that we initialized a boolean
approvalDone variable? After the "Start an approval" action, I'll add a "Set variable" to update this variable to true -- this will be used to "signal" to the other branch that the approval is completed, and no more notification reminders need to be sent. (Without doing this, we might continue to send mails indefinitely!)
Now we can focus on the reminder aspect. I don't want to remind the approvers as soon as the approval is created (they have the Flow actionable approval email for that), so I'll add a "Delay" action to give them a whole day to approve. Once the day is up, I now want to loop until the approval is complete. I'll use "Do Until", where the exit condition is the
approvalDone variable becoming true. The variable will be checked at the start of every loop iteration, and once the approval is complete and variable set to true, it won't execute another iteration. (Note that based on how long you expect the approval to be active, and how often you want to send reminders, you may need to adjust the limits on the "Do Until" to make sure it gives you enough retries).
The first action we'll do in the loop is to send the email, so I've set up a basic "Send an email" using Office 365 that includes the link to the file and a friendly reminder message. I can use the
approversList variable to make sure that the email is sent to the same set of people to which the approval is assigned. After the email is sent, I want to wait again before sending it again. I'll Delay for another day, but you could just as easily do something custom -- send more frequent reminders after a while, cc their manager after some number of reminders, check if the day is a holiday/weekend, etc.)
Because the loop will check the condition before executing, if the approvers respond during any of the "Delay" actions, the condition will be checked again before sending either the first or subsequent reminder emails. This avoids sending reminders for approvals that are already complete.
If you wish to play around with this technique, I exported the sample flow so you can import it into your environment. It can be downloaded here.
Parallel branches are a powerful approach to extend a single Flow with business logic/behavior that needs to run concurrently, without splitting logic across multiple Flows.