Friday, September 9, 2011

Create Parallel Task in State Machine Workflow in SharePoint2010

I faced a problem while creating parallel tasks in state machine workflow. My requirement is same as OUT of Box SharePoint approval workflow which allows multiple users to approve the document and when everyone approves the document, document moves to next state which is approved.

All the articles pointed me that this is possible in sequential workflow.

Here is the thread which explains the problem, I would no be investing much time to explain the problem

I downloaded the code sample available at Microsoft site which is basic state machine workflow. Following is the link.

Modifications to the code are as follows:
  • Add a new state at level 2.
  • In the state initialization, create two tasks with different Correlation token, task ids and task properties.
  • Now add two event driven activity.
  • Keep flags for each parallel task
  • Added OnTaskChanged event driven activity, On Invoked event updated the associated flag to true.
  • Put an IF block and check if all the flags are true, then set state workflow to next state.

I found this easy to implement, though manual code is involved which should be done via a parallel activity.

Code can be downloaded from here.

1 comment:

  1. still just a fixed number of tasks though. if you wanted to have N tasks, as per what the replicator does, and have them run in parallel, you're F'd.