Project Description
A custom task creation activity that can be used in a sequential or state machine workflow. The activity was specifically developed to handle task creation, update, delete, email and completion within the Replicator activity to create tasks in parallel.

Overview
I was given a task to develop a workflow that upon kick off reads items from other lists for assignment, business areas and notification lists and spwan multiple tasks dynamically in parallel. The workflow is set to be completed when all the tasks are actioned by their assignees without waiting one task to be finished before the next task is created.

How it works
Thankfully WF comes up with a looping activity to run a specific child activity multiple times and is called Replicator activity. It has its own challenges and limitations to work within for instance, you can only add one activity as a child of a Replicator activity.

The first and foremost thing one has to get their head around is to understand what happens behind the scenes when the replicator is set to run in parallel mode. And not the least, it is important to understand the crucks about workflow execution specially for SharePoint world. Now there is heaps of documentation on MSDN on it so I wouldn't go into details but I would mention a few which I had to face when using Replicator.
  • One activity per replicator
  • Custom activity is a must if you want to run it in parallel.
  • Bubble up all dependency properties and events from your custom activity.
Challenges
Developing, deploying and to getting to debug the workflows in SharePoint is itself a painful task and I humbly recommend to put together all pieces first and make it to the stage when you are ready to add up or make changes and easily able to deploy your changes to your workflow. This makes debugging/testing easy.

Components
This codeplex project has two parts one being a custom activity that can be used in any workflow project and the workflow part as to show you how to use the activity. I read a lot of blogs and looked at msdn examples specifically the ECM Toolkit from where I chose to write up my custom activity that manages the life cycle of SharePoint tasks as oppose to use/extend WSSTaskActivity due to following reasons:
  • It does not use CreateTaskWithContentType activity
  • It does not send email notifications
  • TaskCreationProperties cannot be used in replicator when running in parallel to set task properties.
Howerver, I have reused some code from WssTaskActivity sample provided by ECM Toolkit.

Useful Links Issues
Built-in OnTaskCreated Activity breaks the connection/correlation between created tasks and the workflow which results in OnTaskChanged and OnTaskDeleted activity handlers never get fired. The TaskCreated handler is triggered for the first task and never for the rest of the tasks because the in-memory object gets staled and you will see the following error in the ULS log:
  • Item has already been added. Key in dictionary (<GUID>)
  • RunWorkflow: System.Workflow.Activities.EventDeliveryFailedException: Event "OnTaskCreated" on interface type "Microsoft.SharePoint.Workflow.ITaskService" for instance id "<GUID>" cannot be delivered.
It seems that the workflow manager lose object reference to the registered tasks. Doug explains this bug in his blog as nasty SharePoint workflow bug at http://www.elumenotion.com/Blog/Lists/Posts/Post.aspx?ID=69. The workaround this problem is to avoid using OnTaskCreated activity when working with Replicator.

Last edited Mar 18, 2010 at 6:20 AM by nicodemeus, version 8