Techbubbles

Creating Parallel Workflow in SharePoint 2010

 

This post explains how to create parallel tasks in SharePoint 2010 workflow. The idea is we are going to assign the tasks to people and they can complete them in any order without having a dependency on one another. In this example we create a custom SharePoint list which contains a vacation request details looks as below

image

The Request contains a title field which represents the type of request and then two people(Team Lead and Department Head) who requires to approve this request.

We then create a task list as shown below

image

This list looks empty as we have not started workflow on the custom Share Point list. Now we run the workflow on list by selecting the title

image

As soon as you start the workflow, the task list will be updated with details as shown below

image

Now the assignee can pick this task and can respond with status

image

Now we can see the status update in SharePoint custom list

image

If you click on the Status value then you can see the detailed workflow history

image

Now we will look at the code-behind this workflow and designer

image

The key thing is how many parallel tasks that you are going to create in your workflow, in this case two(CreateTask1 and CreateTask2). We then use the parallel activity to run the  task change in parallel.

image

Once the tasks have been created, the events  onTaskChanged1  and Changed2 waits for some one to edit their task and each time they edited these events will check whether the task is completed or not. If the task is complete then we fall through the CompleteTask1 activity.

Each event is embedded in one single sequence activity. These sequence activities are inside the parallel activity. Important thing is create the tasks outside the parallel activity.

The code for create task activity

image

Here we are getting the SPUser for TeamLeader and Employee fields. Each time an event will  fire to check the task status.

image

image

This pretty standard coding inside the SharePoint 2010 workflow. When task is complete we simply mark them as complete as shown below

image

The key thing is how does the workflow know which task to deal while executing in parallel? We can know this by workflow correlation tokens. In this case click on CreateTask1 and set the correlation token as shown below

image

Now click on the onchangedevent1 and set the same correlation task

image

similarly for completeTask activity.

image

What is the role of these tokens?  Tokens helps the workflow to understand that the task created in this activity should be managed in the activities in parallel activity.

Recap the steps in SharePoint 2010 parallel workflow

Creating the tasks first and then parallel activity containing the sequence activities which in-turn containing a while loop to test the task status and finally a complete task activity.


Share this post :


Related Posts:

%d bloggers like this: