Vadim Tabakman

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

Posted by Vadim Tabakman Monday, February 6, 2012 7:54:00 PM Categories: Call Web Service Nintex Nintex Workflow User Defined Actions
Copyright Vadim Tabakman
Rate this Content 0 Votes

Comments

Thursday, February 16, 2012 5:54:57 PM
Aaron Sew Hoy

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Vadim,

I am actually working through this exact functionality at the moment. I initially started by using the NintexWorkflow webservice method TerminateWorkflowByNameForListItem. I had assumed that setting the parameter terminatePreviousInstances = true, would take care of the multiple instances issue; however, it just does not seem to work.

I have just tried to download the 2010 version of your workflow but for some reason I am getting a 404 error page. Is there somewhere else I can get this from?

Cheers

Friday, February 24, 2012 8:01:50 AM

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Aaron,

I've fixed the links.  Sorry about that. 

You should now be able to right-click and download them.

cheers,

Vadim

Wednesday, May 9, 2012 5:28:03 AM
Rinze Smit

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi,

Thanks for this terrific article.

I've got a question considering the UDA: Why do I need to get the workflow-name into a parameter? It's not used is it?

I suppose I have to configure the 'condition' in the For Each with the parameter "Workflow Instance ID", but can't see where I need the name.

 

Thanks

Wednesday, May 9, 2012 8:54:39 AM

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Rinze,

you're right.  I was planning on using it to log some information afterwards, but didn't end up using it.  Feel free to take it out if you don't need it.

Wednesday, May 16, 2012 10:13:24 PM
DaveLev

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Way cool, Vadim, thanks! Wish Workflow 2007 had UDAs.

Tuesday, November 20, 2012 10:49:51 PM
sudheer

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi,
I have created a workflow and there based on the 3 Conditions i am starting 3 workflows.
the child workflow is starting and the parent workflow is showing status as "In Progress"
after the completion of child workflow,the child workflow status is in Complete and the parent workflow status is going to "Error occurred". so that i am unable to start the workflow again unless i terminate it manually.

 

Tuesday, November 20, 2012 11:23:13 PM
Vadim Tabakman
Gravatar

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi sudheer, Look for workflow infrastructure errors messages in your SharePoint logs. There should be somet there that explains why it errors. Cheers, Vadim
Saturday, December 15, 2012 7:33:52 AM
Dave Kuehling

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Vadim,

Could you use something similar to what you have on a site workflow?

Thanks!!

Dave

Saturday, December 15, 2012 1:39:08 PM

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Dave,

Currently, I don't think there's a way to do this, since there's no way to terminate a site workflow with the Nintex Workflow web service.

cheers,

Vadim

Wednesday, December 26, 2012 2:41:28 AM
Jay

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi,

Thanks for the wonderful post. I used it and it worked perfectly. But, now out of sudden, the UDA web service does not return any result though there is workflow running in progress.

Can you please advise what should i check/anything that i missed.

Regards,

J

Wednesday, December 26, 2012 8:16:53 AM

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Jay,

nothing jumps out at me.  I'd suggesting puttng in some Log actions into your UDA to see if it's going in there and what information is being used.

cheers,

Vadim

Thursday, January 10, 2013 3:02:58 PM
Kyle

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Vadim - Will the termination of the workflows still generate a cancellation notice for pending tasks?

Thursday, January 10, 2013 4:36:28 PM

re: Nintex Workflow - Terminate Previous Instances of a Workflow

hi Kyle, yes it will seems out the emails, unless you disable error notifications. cheers, Vadim
Monday, July 1, 2013 5:58:10 AM
Yevgeny

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hello Vadim,

does workflow instance id depends from the workflow's version?

Thank you.

/Yevgeny

Monday, July 1, 2013 4:03:41 PM
Russ Hancock

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Vadim,

This looks like exactly what I need, but the downloaded UDA file has a .nwf extension, and hte UDA import errors saying it is expecting a .uda file... simply renaming the extension doens't work... what am I doing wrong!?

Cheers

Russ

Monday, July 1, 2013 4:03:53 PM
Russ Hancock

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Vadim,

This looks like exactly what I need, but the downloaded UDA file has a .nwf extension, and hte UDA import errors saying it is expecting a .uda file... simply renaming the extension doens't work... what am I doing wrong!?

Cheers

Russ

Tuesday, July 2, 2013 11:48:40 AM

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Russ,

in the Manager User Defined Actions, click on Create in the ribbon.  Then on that workflow designer page, click import and you'll be able to import this User Defined Action.

cheers,

Vadim

Monday, March 17, 2014 10:06:37 AM

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Vadim,

I tried using this but it's not cancelling, or apparently even finding running workflows. If I change the "stateFilter" to "All", it will cancel all completed workflows but still not the running workflows.

The workflows I am trying to cancel are generally either stuck on "starting" or have an "error occurred" status.

Any idea?

Tuesday, August 5, 2014 8:48:02 AM
Gabe WOrden
Gravatar

re: Nintex Workflow - Terminate Previous Instances of a Workflow

I receiving an error soap;ServerServer was unable to process request --. Detected use of a workflow constant 'test' which does not exist or is not allowed for the current user in the action 'Call web service'.  The workflow cannot be published.  Please assist me with this error. 

Tuesday, August 5, 2014 9:03:34 AM

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Gabe,

the workflow you are trying is using a Nintex Workflow Constant called "test".  You don't have a workflow constant of that name, which is why this is failing.

You either need to create the appropriate workflow constant in Site Settings > Manage Workflow Constants, or you need to update the appropriate action that is using that constant, and use something else.

cheers,

Vadim

Tuesday, August 5, 2014 9:10:05 AM

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Gabe,

specifically, it's the Call Web Service action that is using a test constant which is of type "Credential".  So you'll need to create one of those.

cheers,

Vadim

Wednesday, March 18, 2015 6:16:21 AM
Dejan Dujak
Gravatar

re: Nintex Workflow - Terminate Previous Instances of a Workflow

 HI,

I am not able to import SP2013 version. As UDA.

I am following normal steps: Manager User Defined Actions, click on Create in the ribbon.  Then on that workflow designer page, click import and you'll be able to import this User Defined Action.

Error: "The imported workflow is a List Workflow and can not be used as a User Defined Action."

Please any help is welcome.

 

Wednesday, March 18, 2015 8:15:19 AM

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Dejan,

try downloading it again.  I had the link pointing to the wrong file.

cheers,

Vadim

Wednesday, April 1, 2015 1:39:24 AM
Massimo
Gravatar

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Vadim. I've the same problem of Dejan

I am not able to import SP2013 version. As UDA.

I am following normal steps: Manager User Defined Actions, click on Create in the ribbon.  Then on that workflow designer page, click import and you'll be able to import this User Defined Action.

Error: "The imported workflow is a List Workflow and can not be used as a User Defined Action."

I tried to rename the file with extension .uda but it gave the folliwing error:

Application error when access /_layouts/15/NintexWorkflow/ImportUserDefinedActionConfirm.aspx, Error=File contains corrupted data.

Wednesday, April 1, 2015 1:53:16 AM
Massimo
Gravatar

re: Nintex Workflow - Terminate Previous Instances of a Workflow

 

Hi Vadim,

I've the same error of Dejan.

I am not able to import SP2013 version. As UDA.

I am following normal steps: Manager User Defined Actions, click on Create in the ribbon.  Then on that workflow designer page, click import and you'll be able to import this User Defined Action.

Error: "The imported workflow is a List Workflow and can not be used as a User Defined Action."

I tried to rename the file Terminate_Previous_Instances_UDA2013.nwf with the extension .uda but it gave the following error:

Application error when access /_layouts/15/NintexWorkflow/ImportUserDefinedActionConfirm.aspx, Error=File contains corrupted data.

Can you help me please ?

 

 

 

Wednesday, April 1, 2015 8:21:33 AM

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Massimo,

you're trying to import the workflow and not the User Defined Action. Try downloading the UDA and importing that.

http://vadimtabakman.com/Data/Sites/1/vtdownloads/blog/terminatepreviousinstances/Terminate_Previous_Instances_UDA2013.nwf

cheers,

Vadim

Wednesday, April 1, 2015 10:19:42 AM
Massimo
Gravatar

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Vadim,

thank you for your quickly response.

I resolved creating first the user defined action and later importing the Terminate_Previous_Instances_UDA2013.nwf file.

Massimo

 

 

Monday, July 20, 2015 6:17:32 AM
Joanna
Gravatar

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Vadim - Is there a way I can use this to terminate all instances of the newest version of a workflow? For instance, I will have a version of a workflow that is running on an item, completing certain tasks, but want to make edits to the workflow for future tasks; whenever the existing item updates a field, the newer version of the workflow kicks off, duplicating tasks that are already completed. I would like to shut off all of the newest workflow instances to avoid this duplication.

Monday, July 20, 2015 6:29:34 AM
Joanna
Gravatar

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Vadim - Is there a way I can use this to terminate all instances of the newest version of a workflow? For instance, I will have a version of a workflow that is running on an item, completing certain tasks, but want to make edits to the workflow for future tasks; whenever the existing item updates a field, the newer version of the workflow kicks off, duplicating tasks that are already completed. I would like to shut off all of the newest workflow instances to avoid this duplication.

Monday, July 20, 2015 8:17:29 AM

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Joanna,

I would recommend that you modify your workflow so that the first thing it does is check if there are previous instances running and if there are, just end the current workflow and let the previous instance complete.

cheers,

Vadim

Wednesday, July 22, 2015 11:40:47 AM
Joanna
Gravatar

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Thank you, Vadim. I am trying to use the workflow logic you show above to check for previous instances (and, if so, to end the workflow), however I am not sure what to put into the "Get Running Workflow Instances Information" action, the Regular Expression action, and the Query XML action. Would you mind showing a screenshot of the settings for each of these?

Many thanks,
Joanna

Thursday, July 23, 2015 4:50:43 AM
Joanna
Gravatar

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Thank you, Vadim! Can you tell me what the configuration for each of the workflow actions should look like (especially calling the web service, regular expressions, and querying the XML)?

Thursday, July 23, 2015 12:23:13 PM

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Joanna,

I would keep it simple.  I would do everything in the workflow above, but at the end where there is the Call Web Service action that terminates the found instance, I would do nothing and the let the current workflow continue and end.

 

Alternatively, if it doesn't find anything, it'll go down the right branch and the rest of workflow logic can be in there.

cheers,

Vadim

Tuesday, July 28, 2015 8:57:54 AM
Joanna
Gravatar

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Thanks, Vadim. Can you share exactly how I should configure the Call Web Service, Regular Expression, and Query XML actions in the workflow I create? Would you mind posting screenshots so that I know how to configure each to make these work appropriately (I am not very familiar with these actions).

Wednesday, July 29, 2015 4:27:24 AM
Joanna
Gravatar

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Thanks, Vadim. Can you share exactly how I should configure the Call Web Service, Regular Expression, and Query XML actions in the workflow I create? Would you mind posting screenshots so that I know how to configure each to make these work appropriately (I am not very familiar with these actions).

Monday, August 24, 2015 3:07:54 AM
Yoram Katz
Gravatar

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hello Vadim,

This piece was extremely useful for me.

However, I found that in some cases I was plagued also with past errored ("Faulting") instances, so I added another deletion branch for them.

 

BTW, is there a way for bundling "Running" and "Faulting" into a single web service call?

I tried a few sensible hunches ("or", "|") but failed.

Many Thanks,

YK

Monday, August 24, 2015 8:27:57 AM

re: Nintex Workflow - Terminate Previous Instances of a Workflow

Hi Yoram,

I don't believe there is, since you're terminate a workflow by it's instance ID.  It's one termination per instance.

cheers,

Vadim

You must sign in to this site to post comments.
Already Registered?
Sign In
Not Yet Registered?
Register





 

Statistics

  • Entries (249)
  • Comments (1729)

Categories