Update Multi-lookup field in SharePoint 2013 Workflow

I was developing a SharePoint 2013 workflow using Visual Studio (SharePoint add-in) and I got following error while creating/updating list item with multi-lookup column.

An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected.

I searched a lot but unfortunately I could not able to find solution anywhere. Then I remembered that SharePoint 2013 Workflow communicate with list using Rest API and I found how the API expects value for multi-lookup field.

  • Single Lookup value format: LookupFieldName: LookupIdVal
  • Mutiple Lookup value format: LookupFieldName: {"results":[LookupIdVal1,LookupIdVal2] }
Now the challenge is how to provide this input since it is in JSON formatted string. Initially I thought that I have to provide JSON formatted string and tried to search for the solution but no luck. I have no clue how to build this. Got tired but at last, I got a clue from the following blog. Here, he is building a dynamic value to update managed metadata field.

http://www.jrjlee.com/2015/01/custom-workflow-activity-for-setting.html

Finally I was able to build results string as below. I have created a variable called vCollLookup and the variable type is DynamicValue.


Click on View properties, provide value for results array.


Behind the scenes the workflow sends this dynamic value in below format.

{"results":[LookupIdVal1,LookupIdVal2] }

Finally, I have used this dynamic value in UpdateListItem activity as below.


Hope it will help others.

Comments

Popular posts from this blog

Switch from Classic to Claims Authentication in SharePoint 2010

How to query list data using web service