December 14, 2015
While SharePoint 2013 now includes looping functionality in workflows built through SharePoint designer, this was not an out-of-the-box capability of SharePoint 2010. However, using the following method, it is possible to simulate a loop using two SharePoint Designer workflows that trigger each other. Since a workflow cannot trigger itself (i.e if the workflow is set to run on item change and that workflow itself changes the item, it will not re-trigger itself to run).
Note: Although it is probably more elegant to create a custom Visual Studio workflow with this looping ability, the following solution requires no code and can be created entirely using SharePoint Designer 2010.
I will use the following scenario: implementing a daily reminder email to be sent until a task is set as complete.
First, there are some hidden columns that you will need to add to your list. In order to hide the columns from your users, you will need to either customize your list form with InfoPath, or use content types.
You will need:
A checkbox column called “FirstEmailSent” with a default value No
Another checkbox called “SendMail” with a default value Yes.
A number column called “EmailReminderCount”
There will be a main workflow that sends out your initial email and any subsequent reminder emails. (For my workflow, I needed to have different text in the intial “You have a new task” email from the “You have a task that needs to be completed” email).
This workflow will be initiated on Item Create and Item Update.
First, the workflow will need to check the status of the task, and stop if the task is complete:
Then, the workflow will need to check if the first email has been sent:
If first email has not yet been sent, the workflow will send the email. It will then need to update the item to mark “FirstEmailSent” to yes and “SendMail” to no.
Now let’s move for a moment to the second workflow. This workflow starts only on Item Update. After the first email gets sent and the item is updated as indicated above, this workflow will initiate. The overall workflow should be set up like this:
Essentially, whenever the item “SendMail” is Yes an action will take place in the first workflow, for example, sending the initial email, a reminder email, or stopping the workflow. If “SendMail” is no, then the second workflow updates the item again to re-initiate the main workflow.
In my scenario, I have the workflow add 1 to the EmailReminderCount field, then update the item with the new Email count. It will also set “SendMail” back to Yes, so that the main workflow knows it needs to send an email. In updating this item, the main workflow is re-initiated.
Back to the Main Workflow
Now that our initial email has been sent and the secondary workflow updated the EmailReminderCount field, the main workflow has re-started. It will skip the first two steps, as the task is still active and now the First email has been sent.
This is the remainder of the workflow logic:
The workflow now has sent the first email, and our secondary workflow set SendMail back to Yes. At this point, the main workflow will now pause for 1 day. At the end of the 24hrs, the workflow checks to see if the task has been completed.
If the task has been completed, then the workflow will stop – no reminder emails need to be sent. If the task is still incomplete, then the workflow will email the reminder email (here’s where you can include a different message for your reminder emails). The workflow will then update the current item so that SendMail is No. Updating the item causes the secondary workflow to run again, which will update the EmailReminderCount field. This will re-initiate your primary workflow, which will jump back to the reminder logic, pause, and then send another reminder email if the task is still incomplete. And so on.
Implementing this solution does not prevent you from having further workflows on your list (perhaps you have a workflow that manages updating task status automatically).