mittex89
Canvas Initiate

Terminate workflows automatically

Hi all,

in our SP 2016 farm we have many Nintex workfows running. Unfortunately, many users ignore the message that a workflow has ended unexpectedly. My question is now, why is there a "error" status and why do you always have to end a workflow manually - terminate this workflow? Furthermore, is there a setting (maybe with PowerShell or in the CA) that a workflow terminates itself after it ends unexpectedly.

I hope I get some answers because this is bothering me for quite a while now.

 

BR, Alex

0 Kudos
Reply
3 Replies
kchaluvadi
Workflow Veteran

Re: Terminate workflows automatically

Rather terminating the errored workflows, I would suggest to find the root cause for erroring the workflows. Issue could be with workflow logic, or  Nintex Services or Nintex related timer jobs.

Reply
jmoore
Forms Fledgling

Re: Terminate workflows automatically

 

Here is a script to terminate all workflows on task items with a due date of more than 7 days in the future.

 

#Get Site COllection
$siteCollection = Get-SPSite "http://sharepoint.dev.com/sites/site/"

#Your Shaeproint Site URL
$spWeb = Get-SPWeb "http://sharepoint.dev.com/sites/site/sub-site";
$spWeb.AllowUnsafeUpdates = $true;
$WFManager=$Web.site.WorkFlowManager

$deadline = (get-date).AddDays(7)

foreach($subSite in $spWeb.Webs)
{
$subSite.Title
$subSite.AllowUnsafeUpdates = $true
$WFManager=$subSite.site.WorkFlowManager
$list = $subSite.Lists["Requirements"]

foreach ($listItem in $list.Items)
{
$duedate = [datetime]$listItem["Due Date"]
if ($duedate -gt $deadline)
{
foreach ($workflow in $listItem.Workflows)
{
# Write-Host "internal State: " $workflow.InternalState
if ($workflow.InternalState -ne "Completed")
{
# Cancel Workflow
[Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($workflow);

# start workflow
$WFAssociation = $list.WorkFlowAssociations | where {$_.Name -Like "*Requirement Reminders"}
Write-Host "wf association $WFAssociation"
$WFManager.StartWorkFlow($item,$WFAssociation,$WFAssociation.AssociationData)
}
}

}

}

$subSite.Dispose()
}

$spWeb.Dispose()

0 Kudos
Reply
mittex89
Canvas Initiate

Re: Terminate workflows automatically

Hi,

that's not that easy: we also have users which have no programming skills who also build worklfows or are allowd to bulid them. Unfortunately, those WFs often have some design flaws or they don't test the WF well and so errors occure once in a while. The WFs designed by the IT department run like a charm - so its not timer related.

 

BR, Alex

0 Kudos
Reply