I’ve recently had a need to model a looping workflow with a SharePoint Designer workflow. Designer doesn’t have a ‘Start Workflow’ action available by default, so I installed the Useful SharePoint Designer Workflow Activities on Codeplex.
My workflow would be designed like this
-
Collect Data From Users with Task Form
-
Set Workflow Variable to Step 1 Task ID
-
Check for repeat condition on Above Task
-
Start a new instance of this workflow
-
- (Workflow Done)
Looks great, but when running this workflow, I kept getting the following error:
Exception from HRESULT: 0x8102009B
at Microsoft.SharePoint.Library.SPRequest.AddWorkflowToListItem(String bstrUrl, String bstrListName, Int32 lItemID, Int32 lItemLevel, Int32 lItemVersion, Guid workflowPackageId, Guid& pWorkflowInstanceId, Guid workflowTaskListId, String bstrStatusFieldInternalName, Int32 lAuthorId)
I searched around and found out that you cannot start an instance of a workflow on an item when the same workflow is already running on that item. Lucy’s blog had a code sample which checked the target item for the duplicate WF and removed the WF if it was found. I wanted to keep the data from the first workflow, and this would remove it. Not exactly what I wanted.
Here’s a simpler approach I took:
Modify the original workflow (Workflow A)…
-
Collect Data From Users with Task Form
-
Set Workflow Variable to Step 1 Task ID
-
Check for repeat condition on Above Task
-
Start a new instance of the LookBack workflow
-
Stop this workflow and log the message ‘Completed – Looping’
-
-
(Workflow Done)
Create a second workflow called ‘LoopBack’:
-
Pause for 1 minute
-
Start a new instance of Workflow A
-
(Workflow Done)
I can start an instance of LoopBack at the same time as Workflow A. Then, LoopBack waits while Workflow A completes. After that, it starts Workflow A over again. The pause is there since Workflow A takes some time to fully complete.
Note, if you’re not running SP1, the Pause for 1 minute step will take 30 minutes to complete. Installing SP1 will fix this issue.
This is a really simple way to model a looping workflow without going into Visual Studio.