Tuesday, October 30, 2012

Workflow assembly to cancel waiting workflows - Part 2

In my last blog, I posted a code for a custom workflow assembly that updates the status of waiting workflow to “Cancelled” when a new instance of the workflow is created.
I did not like the fact that I need to pass the name of workflow as a parameter to the assembly. Then this thought across my mind that I may be able to use this workflow for some other scenarios. For e.g What will happen if I deactivate an account which have one or more workflows in a waiting status?
Personally, I would like to cancel all waiting workflows if I deactivate the account. So I change the code.
Now this workflow assembly can be used in 2 different scenarios.
  1. If I pass the name of the workflow to the assembly. It will update the status of waiting instance of the workflow to “Cancelled” .
  2. If I pass nothing, then it will update the status of all the waiting workflows to “Cancelled” for an entity regardless, of the name of the workflow. In the following screen shot, I am leaving the work flow name empty.
Click here to download the workflow.zip. I have uploaded the whole solution.