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
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
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
As soon as you start the workflow, the task list will be updated with details as shown below
Now the assignee can pick this task and can respond with status
Now we can see the status update in SharePoint custom list
If you click on the Status value then you can see the detailed workflow history
Now we will look at the code-behind this workflow and designer
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.
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
Here we are getting the SPUser for TeamLeader and Employee fields. Each time an event will fire to check the task status.
This pretty standard coding inside the SharePoint 2010 workflow. When task is complete we simply mark them as complete as shown below
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
Now click on the onchangedevent1 and set the same correlation task
similarly for completeTask activity.
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 : |
[…] on one another. In this example we create a custom SharePoint list which contains a vacation… Read more… Categories: .NET SharePoint Share | Related […]