cancel
Showing results for 
Search instead for 
Did you mean: 

How to bulk cancel list item workflows with a status of "Error Occurred"

aaron_labiosa
Nintex Newbie
21 8 11.4K

Products: Nintex Workflow 2013

A common request we see is "How do I cancel/terminate a group of list item workflows that are in a state of 'Error Occurred'?" This article provides instructions on how to accomplish this.

Run the below (attached as well as a *.txt file for your convenience) PowerShell script (PowerShell ISE works well) from a SharePoint Server:

PowerShell Script

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

function Cancel-SPWorkflow(){
PARAM
(
[Parameter(ValueFromPipeline=$true)] [Microsoft.SharePoint.Workflow.SPWorkflow] $SPWorkflow
)

BEGIN {
  }

END {
}

PROCESS {
        [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($SPworkflow)
    }

}

function Get-SPWorkflow(){
PARAM
(
[Parameter(ValueFromPipeline=$true)] [Microsoft.SharePoint.SPListItem] $SPListItem
)

BEGIN {
  }

END {
}

PROCESS {
        $SPListItem.Workflows
    }

}

$(Get-SPWeb http://contoso.com).Lists["DocumentLibrary"].Items | Get-SPWorkflow | where {[String]$_.StatusText -match [String]"Error"} | Cancel-SPWorkflow

To use the script, replace http://contoso.com and DocumentLibrary with the URL of the site and list title you wish to execute the script against.

For the Site Workflow version of this article go here: How to bulk cancel site workflows with a status of "Error Occurred"

8 Comments
ronald_dartsch
Nintex Newbie

Hi Aaron,

I tested this on a German SharePoint 2010 Server but nothing happens.

Is there a possibility to bulk cancel errored workflows in SharePoint 2010?

Best Regards

Ronald

tolbrich
Nintex Newbie

Hi Aaron,

thank you for this article and PS script.

I used it successfully quite some time in SP2016 to cancel NW2016 workflows for different reasons.

Today I had to cancel all workflows in a large list and a user complained about lots of notifications.

Is there a way to prevent sending email notifications to the owner/creator/approver when cancel the workflows?

Thanks

Thomas

aaron_labiosa
Nintex Newbie

There is a SharePoint setting that handles workflow notifications. It can be modified in Central Administration if I recall correctly.

tolbrich
Nintex Newbie

Thanks Aaron.

I found this setting in CA. The same setting is also available in the Nintex Site collection settings either for the whole Site collection or for the Web level.

Very useful to temporarily turn error notifications off.

logan0035
Nintex Newbie

This looks like what I am looking for except I wan to add a time component to it. So if something was created 12/31/2017 or prior I need to cancel the workflow. Is there a good way to do that?

Thanks,
Josh

tolbrich
Nintex Newbie

Hi Aaron,

I have the same question like Josh McCain.

I need to cancel all running workflows started prior a certain date.

This PS script allows to cancel workflows with a certain status.

Do you or does anyone of the community know how to update the Where clause in the script to filter for workflows older then a certain date?

Thank you.

Thomas

jopete19
Nintex Newbie

@tolbrich Were you able to find a script that does what you were asking?

 

I have a list that has a bunch of workflows in a "running" state that I would like to cancel, but can not cancel any current items. 

tolbrich
Nintex Newbie

Hi jopete19,

thank you for the Kudo but I did not find such script. In the end I only canceled error workflows.

Best Regards

Thomas