We are using SharePoint 2016 on-premise. I setup a list workflow (Designer 2010 workflow) to send email to "assigned to" field in the item. Then I prepared a PowerShell script to loop through the list and start workflow on each item if the status=Active
.
However, whenever I tried the same PowerShell error returned.
Exception calling "StartWorkflow" with "3" argument(s): "Unable to synchronously deliver start event via a manual-start workflow."
Here is part of my PowerShell script:
$web = Get-SPWeb $weburl -AssignmentCollection $spAssignment
$site = Get-SPSite $siteurl
$listToloop = "Issues";
$web.AllowUnsafeUpdates = $true;
$wfToStart= "sendemail"
$list = $web.Lists[$listToloop];
$manager=$site.WorkFlowManager
$association=$list.WorkFlowAssociations | where {$_.Name -eq $wfToStart}
$association.AllowAsyncManualStart = $true
$association.AllowManual = $true
foreach ($item in $list.Items) {
$Lookup = new-object Microsoft.SharePoint.SPFieldLookupValue($Item["Status"])
if ($Lookup.LookupValue -eq "Active") {
$data=$association.AssociationData
$wf=$manager.StartWorkFlow($item,$association,$data)
Write-Output "$wftoStart started on " $item.Name | Out-File $outFile -Append
}
else {
Write-Output $item.Name " - is completed " | Out-File $outFile -Append
}
}
If all the items status are not equal to "Active", no error. For each item with status = "Active"
, the same error will throw repeatedly.
$list.UpdateWorkflowAssociation($association)
after$association.AllowAsyncManualStart = $true
.$list.WorkflowAssociations.Update($association)
.Exception calling "StartWorkflow" with "3" argument(s): "Object reference not set to an instance of an object."