Skip to main content
Nintex Community Menu Bar

I am using SharePoint 2019.  I have a site for which I have created several site workflows using the Nintex workflow product.  Periodically, there will pe a problem where the workflow internal status shows “Failed on Start (retrying)” and the workflow instance continues to show up under “Running Workflows”, though the workflow appears to work correctly when I check the results.  Following is a screen shot:

I am looking for a method of canceling and removing all instances of this workflow (in particular those that show as “running” that are in a “failed on start” condition) in a batch mode with a tool like PowerShell or with some sort of timer job.  I want to do this in a batch mode rather than having to go into each job individually and terminate each one.  I have found PowerShell scripts to terminate running list workflow instances, but I haven’t found much on site workflows.

A bonus would be to schedule something to run automatically on a periodic basis, but I would be happy to have something I could run manually.

Does anyone have such a script or method for doing this?

Thank you!

Hi ​@jsupchurch,

Nintex has the NWAdmin tool to sync the Nintex workflow status with the SharePoint status, but unfortunately, in this instance, it looks like the reverse needs to occur.
Instead of patching the issue, it may be worth contacting Microsoft support to resolve the failed on starting issue. Nintex support may be able to help with the issue, but in the end, this appears to be an issue with the SharePoint workflow engine, which Nintex workflows also use.
 


I agree with Simon that trying to resolve the underlying cause of it giving an error should be the main goal rather than trying to remedy over faults. I have a similar issue with workflows sporadically (like once every few hundred runs) erroring when they should finish and go to completed status.

For the time being if finding an actual fix takes too long or is too difficult, you can do this automatically, at least for errored List workflows (I don't know how to do it for Site workflows). Your list workflow needs a Workflow status column enabled, this can be set in the workflow settings of that specific workflow. With the status column, you can query the contents of that column from another workflow through List Query. With this you should be able to find all items for which the workflow is in a “failed to start” state. You can then use a Webservice Query to forcefully terminate the list workflow.

Unfortunately the workflow status column does not work retroactively if it wasn’t enabled before, you can’t retrieve the workflow status of workflows run before it was enabled.

 

To use the webservice query, connect to {siteURL}/_vti_bin/NintexWorkflow/Workflow.asmx in the Call webservice action, and use web method TerminateWorkflowByNameForListItem. It will terminate that workflow instance and set the status to cancelled so it won’t be considered “running” anymore.


Hi ​@BobR 

Just an FYI, the Nintex workflow web service  TerminateWorkflowByNameForListItem changes the status of the workflow in the Nintex database. It does not change the status in SharePoint, as this column is owned by Microsoft.
 


Hi ​@jsupchurch has your question been answered? 


Thanks to everyone for your replies.  The process I am referring to will be rewritten within the next year and we will be moving to SharePoint 365 from SharePoint 2019.  For that reason, I didn’t want to spend a lot of time diagnosing and correcting the problem with the workflow engine.  That said, ​@SimonMuntz, I agree with your advice that the correct way to solve the problem is to address the workflow issue.  I was simply looking for a way to automate a process of terminating the workflows until I can get the business process migrated to the new environment.  ​@BobR, thank you for the additional info.  Since this is a site workflow, there is no associated list item, so a script to terminate instances of list workflows won’t work in this case.

Thanks again!


Hi ​@MillaZ 

My original question was seeking a way to automatically terminate failed instances of site workflows.  It sounds like that might be more a Microsoft thing than a Nintex thing.  If there is a script or process that can do it, I would still be interested.  I understand that the ideal solution is to resolve the workflow start failure, but I am simply looking for a way to terminate the failed instances automatically with a script.

Thanks!


I ran this request through Microsoft Co-Pilot, and this is what it came up with.

To find and terminate SharePoint 2019 site workflows that have failed with the status "Failed on Start (retrying)", you can use PowerShell with the SharePoint Server-side object model. Here's a script that does this:

⚠️ Important: This script must be run on a SharePoint server with the appropriate permissions and SharePoint Management Shell access.

✅ PowerShell Script

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

# Function to check and terminate failed workflows
function Terminate-FailedWorkflows {
param (
>string]$siteUrl
)

Write-Host "Checking site: $siteUrl"

$site = Get-SPSite $siteUrl
foreach ($web in $site.AllWebs) {
Write-Host "Scanning web: $($web.Url)"
$workflows = kMicrosoft.SharePoint.Workflow.SPWorkflowManager]::GetWorkflowDataForSite($web.Site)

foreach ($workflow in $workflows) {
if ($workflow.Status -eq "FailedOnStartRetrying") {
Write-Host "Found failed workflow on item: $($workflow.ItemUrl)"
try {
$web.Site.WorkflowManager.ForceTerminateWorkflow($workflow)
Write-Host "Terminated workflow: $($workflow.InstanceId)"
} catch {
Write-Warning "Failed to terminate workflow: $($_.Exception.Message)"
}
}
}

$web.Dispose()
}

$site.Dispose()
}

# Example usage
$siteCollectionUrl = "http://your-sharepoint-site"
Terminate-FailedWorkflows -siteUrl $siteCollectionUrl

 Notes:

  • Replace "http://your-sharepoint-site" with your actual site collection URL.
  • This script uses the SPWorkflowManager class to access and terminate workflows.
  • The status "FailedOnStartRetrying" is a .NET enum value. If it doesn't match directly, you may need to inspect the actual enum or use its numeric value.

Reply