1

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.

9
  • Is the user running this script has full control access on site? Jul 29, 2019 at 9:16
  • @GaneshSanap yes, I am running the script within app server using farm admin
    – Mark L
    Jul 29, 2019 at 9:22
  • Try adding $list.UpdateWorkflowAssociation($association) after $association.AllowAsyncManualStart = $true. Jul 29, 2019 at 9:24
  • Is it working for you? Or try adding $list.WorkflowAssociations.Update($association). Jul 29, 2019 at 9:52
  • After change, the script is throwing another error: Exception calling "StartWorkflow" with "3" argument(s): "Object reference not set to an instance of an object."
    – Mark L
    Jul 30, 2019 at 2:16

2 Answers 2

1

Start Updating your workflow association after setting:

$association.AllowAsyncManualStart = $true
$association.AllowManual = $true

Using:

$list.UpdateWorkflowAssociation($association)

Or

$list.WorkflowAssociations.Update($association)

About StartWorkFlow() Method:

The boolean parameter shows the property isAutoStart.

This method comes with two overloads. The first overload takes an SPListItem object, an SPWorkflowAssociation object, a string, and a Boolean as its arguments and creates a workflow instance on the SharePoint list item or document represented by the SPListItem object from the workflow association represented by the SPWorkflowAssociation object.

The method starts the workflow instance if the Boolean parameter is true. The method returns an SPWorkflow object that represents the workflow instance.

The second overload takes an SPListItem object, an SPWorkflowAssociation object, and a string as its arguments and creates a workflow instance on the SharePoint list item or document represented by the SPListItem object from the workflow association represented by the SPWorkflowAssociation object. This overload automatically starts the workflow instance.

Hope this helps you.

Reference:

  1. SPWorkflowManager.StartWorkflow Method.
  2. Microsoft SharePoint 2007 Workflow Programming - Page No. 339
0

So, this answer makes no sense to me, but I did this:

$manager=$site.WorkFlowManager
$association=$list.WorkFlowAssociations | where {$.Name -eq $wfToStart}
$association.AllowAsyncManualStart = $true
$association.AllowManual = $true
$list.UpdateWorkflowAssociation($association)
$association=$list.WorkFlowAssociations | where {$
.Name -eq $wfToStart}

And it works consistently now. I guess after updating the association it is necessary to reload the association in memory? Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.