This solution can be used for any SharePoint list, including form and document libraries. The only code is in the calculated column.
The requirement was for the workflow to automatically set the due date for the next step in the workflow, but not have that due date fall on the weekend (when the assignee would not be available).
This was applied to several processes where multiple users were involved in contributing to or reviewing a list item, document or form. In order to make the process complete as quickly as possible, the due date for step 2 would be based on X days after step 1 was completed, and step three on X days after step 2, and so on. If a user in the process completes their task early, the workflow can be completed more quickly than assigning all of the due dates at the beginning of the process.
The solution starts with two SharePoint Designer workflows. The first handles the process flow, from step 1 to step 2 to step 3, etc, responding to the change in the Status field (Wait For Field Change In Current Item). The second workflow runs parallel, starting when the list item gets modified. (This works for items that will only get modified once per step. If an item is expected to be modified multiple times per step, you may want to use a flag field that gets set to “yes/true” when the step is completed, then modified back to “no/false” by the first workflow, and use the flag to determine if the second workflow proceeds or terminates.) The Second workflow waits until the due date, then after the wait checks to see if the step has been completed. If not, it sends e-mail(s) to escalate the issue to whomever needs to be notified.
The Due Dates are determined during runtime. As mentioned in a previous entry, workflows have very limited calculation ability. Using a calculated column in the SharePoint list will allow this to work.
In the case of the particular requirement I worked on, the steps in the workflow were assigned an amount of time (in days) for the step to be completed.
The calculated column looks like this:
[Modified] is the modified date (a default column in any SharePoint list), and [Deadline] is the column containing the number of days to complete the step.
WEEKDAY returns a day number (1-7). If the result is one of the weekend days, the calculation adds two days to the Due Date (if it was due on Saturday, it needs two days to bump it to Monday – the next business day; if the Due Date is Sunday, one of the days that the assignee had to complete the step was Saturday, so they will need Monday to make that up, and the next business day is Tuesday).
Have the workflow Pause Until Date, with the calculated Due Date as the date you pause until, before sending the late notice, escalating the problem to the attention of whoever needs to be notified.
Here is the gotcha: Did you want the assignee to have until the end of the day to get it done? If you are using “Date Only” (instead of date and time) and set the Due Date to Tuesday, then Midnight Tuesday morning is when the notice goes out. If this is the case, after the workflow completes the Pause Until Date, set it to Pause For Duration for 17 hours (for a 5 pm deadline, or 24 hours for a midnight deadline, or 16.75 hours if you are evil and want to catch them just before they leave for the day and make them late for dinner).