SharePoint 2013 – Exception calling “StartWorkflow” with “4” argument(s): “”

Today I tried to start a workflow using PowerShell and I got this annoying error:

Exception calling “StartWorkflow” with “4” argument(s): “”

At C:\Users\spsetup\Downloads\StartDocumentLocksWF.ps1:38 char:9

+ $wf = $wfm.Startworkflow($item,$association, $data,$true)

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : SPException

 

I knew that I was doing the right thingย  as this worked for another workflow:

$ver = $host | select version

if($Ver.version.major -gt 1) 

{

ย ย  $Host.Runspace.ThreadOptions = "ReuseThread"

}

if(!(Get-PSSnapin Microsoft.SharePoint.PowerShell -ea 0))

{

ย ย  Write-Progress -Activity "Loading Modules" -Status "Loading Microsoft.SharePoint.PowerShell"

ย ย  Add-PSSnapin Microsoft.SharePoint.PowerShell

}

# Settings

$siteUrl = "https:/ /intranet.mycomp.com/admin"

$web = Get-SPWeb $siteUrl

$list = $web.Lists["Docs"];

#-- Getting a Workflow manager object to work with.

$wfm = $web.Site.WorkFlowManager

#-- Getting the subscriptions

$association = $list.WorkFlowAssociations |Where { $_.Name -eq "Handle Document Locks"}

$data = $association.AssociationData

$wc=new-object system.net.webclient

$wc.UseDefaultCredentials = $true

foreach ($item in $list.Items)

{

ย ย ย Write-Host $item["Title"] $item.ContentType.Name

ย ย  if ($item.ContentType.Name -eq "My Document")

{

ย ย ย ย ย ย ย  $wf = $wfm.Startworkflow($item,$association, $data,$true)

ย ย ย ย ย ย ย  Start-Sleep -Seconds 10

}

}

 

I am not doing anything complicated, just starting a workflow. The workflow that I was starting however didn’t have manual start enabled and therefore I wasn’t able to start it with PowerShell either.

Enabling the manual start and then republishing the workflow and all worked as expected.

ย Note:ย  the same error message will also appear when the workflow is already started.

 

 


Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Related Posts

One thought on “SharePoint 2013 – Exception calling “StartWorkflow” with “4” argument(s): “”

  1. Thanks for the comments about requiring manual start & that the workflow cannot be currently running. Was testing this step as part of a script to stop & restart the workflow, and overlooked the fact that I hadn’t stopped the running instance for my test! Good catch, and useful info I didn’t find elsewhere.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.