• vadim@workflowexcellence.com
  • Utah, United States

Nintex Workflow – Terminate Previous Instances of a Workflow

SharePoint generally won’t let you run 2 instances of the same workflow on the same item.

I know that Vadim, why are you telling me something that we all know???

Did you know that if you are running an instance of “WorkflowA” on an item, and you then go and make a change to the workflow, republish it, you will now be able to run another instance of “WorkflowA” on that item? This is because when you published it, it is given a new version and SharePoint will allow you to run multiple instances of the same workflow, as long as they are different versions.

Well doesn’t that just make things a little more complicated? (rhetorical question). These two instances will share the same workflow status column in the list. Version 1 of the workflow may still be running but Version 2 may have completed, and if you look at the workflow status column, it will say “Completed” because that is from the latest workflow version.

So this brings us to : How do I terminate old running instances?

Nintex Workflow 2007

There really isn’t an easy way to do it in Nintex Workflow 2007. You would need to build the logic of finding out whether there are previous instances still running, and then go through each one and terminate it.

This part isn’t all that hard, but when it comes to putting this logic into each workflow, it does bloat the workflow a little and if later you find a better way of doing it, you need to update every workflow that uses this.

You could save it as a snippet, but the end result is the same. All the logic will go into each workflow and if you find a better way later, you’ll still need to update every workflow that uses this logic.

The workflow looks like this:

I won’t go into the details of every actions. If you have any questions, feel free to post a comment and I’ll do my best to explain.

Basically what it does is :

1. store the current workflow instance ID in a text variable (this is the current workflow and we don’t want to touch it).

2. make a call to the Nintex Workflow web service to find out what running instances of this workflow there are on the current item.

3. remove the XML namespace from the xml returned to us from the web service call.

4. query the xml to pull out only the Workflow Instance IDs.

5. iterate through each ID.

6. if the ID matches the current workflow instance ID, leave it alone.

7. if it doesn’t match, it’s an old version, and we need to terminate it.

8. make a web service call to the Nintex Workflow web service to terminate the instance of the workflow that matches the ID we are looking at.

Download the Nintex Workflow 2007 workflow :

Download Here

Nintex Workflow 2010

The workflow for Nintex Workflow 2010 does exactly the same thing as the Nintex Workflow 2007 one.

It just looks a little different because of the different look of the designer.

Where things get a little easier with Nintex Workflow 2010, is that this looks like a highly reusable bit of logic. So it’s perfect for a User Defined Action.

The reason is, the logic of the workflow above is good, but it would be the first thing you’d want to do in any of your workflows. The rest of the workflow would be the actual business logic that you design. You don’t really want all 10 actions in every one of your workflows, so adding this to a UDA makes it more reusable.

This is what the User Defined Action would look like:

There’s one less action, and that is because from your workflow, when using this action, you will be passing in the current workflow name and workflow instance ID.

Here is what that the parameters window would look like:

When you go to design your workflow, you’ll now see a Terminate Previous Running Workflow Instances UDA action availabe to you. (I could have picked a shorted name).

Drag it onto your workflow:

Then open the configuration for it, and fill in the 2 parameters :

It’s as simple as that.

Again, if you have any questions, feel free to post them on this blog and I’ll do my best to respond.

Downloads

Nintex Workflow 2013

Download the Workflow (NW2010)  – Download and import the workflow into the workflow designer page

Download the User Defined Action (NWF – NW2010) – Download and import the UDA into the Create User Defined Action designer page

Download the User Defined Action (NWF – NW2013)  – Download and import the UDA into the Create User Defined Action designer page

Leave a Reply

Your email address will not be published. Required fields are marked *