سؤال

I have many running workflows in our SharePoint 2016 environment where I have seen - if we go to the workflow settings page from the library settings, there we could see multiple instances of running workflow, however, if I go to the SharePoint library and filter on workflow name column, we don't see any running workflow, only we could see completed or error out workflow status. Then wherefrom these running instances have been shown on the workflow setting page? Below is one of the examples.

Running Workflow Issue

By the way, these workflows have been migrated from SharePoint 2010 -> SharePoint 2013 -> SharePoint 2016

Any thought? We want to clean up these running instances.

هل كانت مفيدة؟

المحلول

1.PowerShell to terminate 2010 workflow.

$web = Get-SPWeb "site collection URL"

$list = $web.Lists["list name"]

$WorkFlowToCancel = "the workflow name"

foreach ($item in $list.Items)
{
foreach ($wf in $item.Workflows)
 {
    #Check for the particular workflow
    if($wf.ParentAssociation.Name -eq $WorkFlowToCancel)
    {  
        #Cancel Workflow
        [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf)                 
    }
 }
}

2.PowerShell to terminate 2013 workflow.

$siteURL = "site collection URL"
$listName = "list name"
 
$spWeb = Get-SPWeb $siteURL
$spList = $spWeb.Lists[$listName]
$spListItems = $spList.Items
 
$wfMgr = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($spWeb)
$wfInstanceSvc = $wfMgr.GetWorkflowInstanceService()
 
foreach($spListItem in $spListItems)
{  
    $wfInstances = $wfInstanceSvc.EnumerateInstancesForListItem($spList.ID, $spListItem.ID)
    
    foreach($wfInstance in $wfInstances)
    {
       write-host("Terminating instances for list item: {0}" -f $spListItem.ID)     
       $wfInstanceSvc.TerminateWorkflow($wfInstance)
        
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top