It appears that there is no easy way to terminate a bunch of workflows in SharePoint.
A SharePoint List containing many items (eg. 100 items), and each item has an instance of the same workflow running on it. For whatever reason, you need to terminate all the workflows. Your only method of doing this now, is to view the workflow history for each item, and terminate the workflow manually.
What I wanted to do with this type of workflow, is create an administration workflow. What this means, is that I want it to be flexible enough, that I can tell it which list I want to focus on and what the workflow name is, and let it go and terminate the workflows. What I don’t want, is to have to take this workflow to each list, and modify it for that list, and publish and run it. So in order to achieve this, I created a list called Batch Terminate Workflows Administration List. It has 2 fields, which are List Name, and Workflow Name.
The Nintex Workflow web service exposes 3 web methods to help with terminating workflows :
In this blog, I’ll focus on the TerminateWorkflowByNameForListItem. The Workflow looks like this :
It’s not an overly complicated workflow. The biggest challenge, is to make this workflow generic. Given that we only have the destination list name, and the Nintex Workflow Query List action only allows you to pick the name via a drop down, we need to find another way to perform a query. The Query List action lets your write your query in CAML, but clicking on the CAML Editor button. Here we see that the query actually uses the List ID (guid), so we need to find this. The SharePoint Lists.asmx web service exposes a GetList web method we can use, in collaboration with the Call Web Service and Query XML actions, to get the ID we need.
Now that we have the ID we want to use, we can use the variable in the CAML query inside the Query List action.
The Query List action, will the store all the Item IDs in a collection variable, and we can now use the For Each action, to iterate through each Item ID, and then call the Nintex Workflow web service to terminate the workflow on that item. The Call Web Service call looks like this :
Files to Download Download the Batch Termination Workflow