SOLVED: Exception calling “StartWorkflow” with “X” argument(s)

Trying to start a SharePoint workflow using PowerShell and I couldn’t get past this error:

Exception calling “StartWorkflow” with “4” argument(s): “Object reference not set to an instance of an object.”

or

Exception calling “StartWorkflow” with “3” argument(s): “Object reference not set to an instance of an object.”

 

NO clue if there is a bug in my farm, but the script below works.  Ended up having to re-get the item when running the workflow. $manager.StartWorkflow($list.GetItemById($item.ID),$assoc,$data,$true)

$web = Get-SPWeb "http://rootSiteCollection.com"
$list = $web.Lists["Shared Documents"]

$assoc = $list.WorkFlowAssociations |Where { $_.Name -eq "tacoWF"}
$data = $assoc.AssociationData
$manager = $web.Site.WorkflowManager

$sQuery = New-Object Microsoft.SharePoint.SPQuery 

#Get all items with an ID greater than 5 
$caml = '<Where><Gt><FieldRef Name="ID" /><Value Type="Counter">5</Value></Gt></Where>'
$sQuery.Query = $caml
$fItems = $list.GetItems($sQuery)

Foreach($item in $fItems)
{
	$manager.StartWorkflow($list.GetItemById($item.ID),$assoc,$data,$true)
}

 

Are SharePoint Designer Workflows Using Custom Features or Solutions (iLoveSharePoint)

Needed to audit a farm to see if a CodePlex solution was being used in SharePoint Designer workflows.  In my case, I needed to see where the iLove SharePoint  solution was being used. The script below is only targeted at one web and is looking for word “ILoveSharePoint” in the XML.

 


if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{
	Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges(
	{

		$resultsarray =@()
		#output file name
		$fileName = "C:\ilsp-" + $(Get-Date -Format "yyyyMMddHHmmss") + ".csv"
		#name of the feature we are looking for
		$wFeatureName = "ILoveSharePoint"

		Function GetFiles($folder)
 { 
			foreach($file in $folder.Files)
			{
				if($file.Name.Split('.')[-1] -eq "xoml")
				{
					$web2 = Get-SPWeb $file.Web.Url
					$wFile = $web2.GetFileOrFolderObject($web2.URL +"/"+ $file.URL)

					if ($wFile.Exists -eq "True")
					{
						$wXml = (New-Object System.Text.UTF8Encoding).GetString($wFile.OpenBinary());
						$nsDetail = $wXml.OuterXml.ToLower()
						
						$wFeatureName = $wFeatureName.ToLower()
							
						if($nsDetail -Like "*$wFeatureName*")
						{
							$outFolder = $folder -replace "Workflows/",""

							$outObject = new-object PSObject
							$outObject | add-member -membertype NoteProperty -name "URL" -Value $web2.Url
							$outObject | add-member -membertype NoteProperty -name "Workflow" -Value $outFolder
							$outObject | add-member -membertype NoteProperty -name "Created By" -Value $wFile.Author
							$outObject | add-member -membertype NoteProperty -name "Created Date" -Value $wFile.TimeCreated
							$outObject | add-member -membertype NoteProperty -name "Modified By" -Value $wFile.ModifiedBy
							$outObject | add-member -membertype NoteProperty -name "Modified Date" -Value $wFile.TimeLastModified

							$global:resultsarray += $outObject
						}
					} 
				} 
			}

			# Use recursion to loop through all subfolders.
			foreach ($subFolder in $folder.SubFolders)
			{
				GetFiles($Subfolder)
			}
		}

		$WebApplications = Get-SPWebApplication

		foreach($webApp in $WebApplications)
		{
			foreach($site in $webApp.Sites)
			{
				if ((Get-SPSite $site.url -ErrorAction SilentlyContinue) -ne $null) 
				{
					foreach($web in $site.AllWebs)
					{
						if ((Get-SPWeb $web.url -ErrorAction SilentlyContinue) -ne $null) 
						{
							$list1 = $web.Lists.TryGetList("Workflows")
							if($list1 -ne $null)
							{
								GetFiles($list1.RootFolder)
							}
						}
					}
				}
			}
		}

		#output file
		$resultsarray | Export-csv $fileName -notypeinformation

	}
)

The workflow could not update the item, possibly because one or more columns for the item require a different type of information.

SharePoint Designer workflow error:
The workflow could not update the item, possibly because one or more columns for the item require a different type of information.

If you look at the workflow history nothing of value is there to clue you into what field is broken.

To track down what field is broken, I added a Pause action to my Step. Then I added a Log message before each action. Doing this helped track down the broken field.

The workflow could not update the item

Once you get the workflow working again, remember to clean up the added Log actions.

In my case, the workflow was trying to update a Person / Group field with an employee that no longer worked at the company.

Office SharePoint Server Standard Site features must be enabled

In SharePoint Designer 2010, I was attempting to create an approval task for an item.  When I tried to added the action to the workflow, I received the following error.

Cannot insert this action. To use task process actions, the Office SharePoint Server Standard Site features must be enabled for this site by an administrator.

At the site and site collection I made sure SharePoint Server Standard Site features was enabled.  Taking it one step further, I also enabled SharePoint Server Enterprise Site features.  Still the workflow wasn’t working correctly.  Navigated back to the site collection features and activated the Workflows feature.  Refreshed SharePoint Designer and all of the actions worked.

Credit goes to Giles Hamson.

http://spandps.com/2012/04/03/spd-2010-cannot-insert-this-action-sp2010-sharepoint-ps2010-msproject-projectserver-in/

Does creating a folder start a workflow?

Does creating a folder cause a workflow to run?

Yes, when you create a folder, SharePoint treats it like you are uploading a new document.

If you only want to run a workflow on documents that are created or changed, you will need to add a step to your workflow.

The workflow condition would be:

If Current Item: Content Type equals Folder

Stop workflow

Doing this will stop the workflow each time a folder is added or changed.

 

Failed to cache field with id “{ }”, overwrite=0

Workflow failed with this error:
Failed to cache field with id “{blah-dae2-4908-80cd-blah}”, overwrite=0

In my list (A) I had a lookup column pointing to another list (B). In B, I had updated a field from Single line of text to Multiple lines of text. The workflow did not like this update. Once I recreated the field as a Single line of text, the workflow started working.

Coercion Failed: Unable to transform the input lookup data into the requested type.

SharePoint Workflow error:
Coercion Failed: Unable to transform the input lookup data into the requested type.

Using a workflow, I was trying to set the value of a Lookup field. Where I went wrong was, setting the Lookup field to a field other than the ID column of the Lookup List.

What??

Quick example:
Created two lists.
Taco and Taco Topping.

Taco Toppings fields: Title, Meat, Cheese, Salsa

In the Taco list, I added a Lookup field to Taco Topping, also adding Meat, Cheese, and Salsa fields.

Now for the workflow.

On the Taco list, create a new SharePoint Designer workflow.

The workflow will contain the following actions: Set Workflow Variable and Update List Item

First we will create the variable
click inside of Step 1, from the ribbon click on Action, then find Set Workflow Variable.
Once it’s added to the workflow step, click on blue workflow variable text.
I named my variable Taco ID and set the type to Number.

Next click on the blue value text.

Here I’m querying the Taco Topping list for the ID field, and filtering by the Title column of the Title fields of Taco and Taco Topping. Think of this a simple SQL select statement with a where clause. Select ID from Taco Topping where Title = Current Item: Title

Next we will add the Update List Item action.
Click below the Set Variable action, then add the Update List Item from the Action button in the ribbon.
Click on the blue this list text.

Here I’m updating field T to the ID from workflow variable Topping ID.
This is what will drive updating our Taco list to the toppings from Taco Topping.

Your workflow should now look like this.

Publish the workflow, all done!

*Be sure to change your workflow settings (in the ribbon) if you want the workflow to run when a new item is added or changed.*

The item is currently locked for editing. Waiting for item to be checked in or for the lock to be released

Workflow error:

The item is currently locked for editing. Waiting for item to be checked in or for the lock to be released.

Working with SharePoint Designer 2010 and InfoPath, I created a workflow to perform an Action once a form was submitted or changed.

The error above was stopping the workflow from running any of the Steps / Actions.

The fix was to add a Wait for Change in Document Check-Out Status Action to the workflow.  This Action should be the first item executed in the workflow.

The item is currently locked for editing

The item is currently locked for editing

Why does this happen?  Assume the workflow is being triggered the millisecond that the form is being written to the library and not waiting for all the data to finish writing.

*Note* Once the form/item is unlocked, it might take a few minutes for the workflow timer to process the item.

Workflow Attach Document to an Item

Can you use a SharePoint workflow to attach a document to an item?
YES!!!

What do you need to make this happen?
SharePoint Designer
ILove SharePoint actions from codeplex.

On the server(s) that your web app is running, you will need to modify the PowerShell execution policy.
set-executionpolicy Unrestricted (Use this link for more info)

In SharePoint Designer add the Execute PowerShell Script action.
Click Script and add the PowerShell script below (make the needed changes to reflect your URL)

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$web = Get-SPWeb "http://sharepointed.com/subsite/"
$filePath = "http://sharepointed.com/subsite/docs/taco.docx"

$spList = $web.lists["Your List or Library Name Here"] 
$item = $splist.GetItemById([*Add the workflows Current Item:ID here*])
$file = $web.GetFile($filePath).OpenBinary()

$item.Attachments.Add($filepath, $file)
$item.Update()

$web.Dispose()

$web = the site you are wanting to work with.
$filePath = file path to the document you are wanting to attach to the item that triggered the workflow.
$spList = List that contains the item we are attaching the document to.
$item = $splist.GetItemById() clear out the text between the (), in here you ware wanting to place ID of the item that triggered the workflow. This will tell the PowerShell script what item we are attaching the document to.