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.

Avatar of Pieter Veenstra

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There's a better way — and I can show you exactly what it looks like. I'm the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I've been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/ Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/ You can contact me using contact@sharepains.com

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.

Discover more from SharePains

Subscribe now to keep reading and get access to the full archive.

Continue reading