(Looping) Timer Workflows Using SharePoint - SharePoint Development & Administration + InfoPath

Sunday, October 18, 2009

(Looping) Timer Workflows Using SharePoint

Timer Workflows

It is often a requirement of a Workflow in SharePoint to monitor and respond to various dates such as a start or due date.

If the timer is not the main function of a Workflow, it can be created as a separate Workflow to that both can run in parallel with full functionality.

Looping Timer Workflows

To have a looping timer workflow (eg. send a daily notification/reminder until a specific condition is met), the workflow must start when an item in the list is changed, and when it is created depending on the scenario.

At the start of the workflow, test if the required condition has been met, and stop the workflow if it has. If the condition has not yet been satisfied, the workflow can continue.

As the workflow will initiate after an item is modified, it is possible for multiple instances of the same workflow to be initiated. To prevent this, a custom (boolean) field is added to the list which is used to determine if an instance of the workflow is already running. When the workflow starts, it first tests if the value of a custom field (eg. "timer_waiting") in the current item is set to true/yes. If true, another instance of the workflow is already running and the current can be stopped. If false, the custom"timer_waiting" field can be set to true/yes to stop new instances from starting until the current is complete.

If the workflow is to continue, perform the required date calculations (current date + 1 day), store in a workflow variable, then wait until the date determined. Send the email, or perform other actions after the workflow has finished waiting (next workflow step).

To complete the workflow, set the field in the current item "timer_waiting" back to false/no to allow a new instance of the timer workflow to start.

If the SharePoint (MOSS 2007) Server has no service packs installed or Service Pack 1 only, updating the field in the current item workflow will cause another instance of the workflow to start, creating the looping functionality. If service pack is installed, a separate list must be used to trigger the first again to enable looping workflows.

For more information about looping workflows in general, as well as the changes to looping workflows made when Service Pack 2 is installed, see Service Pack 2 prevents an on-change workflow from starting itself.

Related Articles

SharePoint Looping Workflow - How to: Loop through and process all items in a list

"The OOB workflow actions provided by SharePoint don't allow a loop to be configured explicitly. Instead, a number of workflows can work together to create a looping affect. Another limitation of Workflows in SharePoint using SharePoint Designer (SPD) is the inability to simply test if the user who initiated the workflow is a member of a SharePoint group, or to test if the value of a field in the item which initiated the workflow is equal to the value of a specific field from any item in a separate list."

How to wait for a change in any list, wait for multiple field changes in the current item (SharePoint Workflow)

This article describes techniques which can be used when developing workflows in SharePoint using SharePoint Designer. They allow a workflow to wait for a field change in an item in another list, or to wait for multiple field changes in the current item before continuing.

SPD Workflow - Test if value exists in any item in SharePoint list - create new item if not found
SharePoint Designer Workflow: How to test if a specific value exists in any item in a list without the workflow stopping due to a "List item not found" error if no items exist with the required value.

How to configure a workflow to start at specific time, then loop / repeat periodically (Daily, Weekly)
The following method can be used to start a workflow at a specific time, then repeat periodically (each day). Periodic Workflow Processing: (send daily email notification or reminder)
A useful implementation of this technique allows you to configure workflows to run as background tasks at a specific time instead of being triggered by a user manually, or after creating or modifying a list item.

SharePoint Workflow Errors: Descriptions, resolutions and Workarounds
The following table lists some of the common errors that can occur in a Workflow developed using SharePoint Designer. A short description of some of the likely causes for each error are also provided.

Share this article:
Stumble This Delicious
submit to reddit

No comments:

Post a Comment