Sunday, 19 July 2015

On change start type Workflow executing on Item Adding with Client Object Model

I was using SharePoint client Object model to add SharePoint list item using dot net.
There is one SharePoint designer List workflow associated and will be executed on updating list item (On changes).
While adding item in SharePoint list, I found that workflow gets executed with adding event. I was surprised to see that why this happening. Because it must be executed on item update not item add event.
I have tried every solution/resolution what I can do (and what I know) like created workflow again, checked every place in my code that how many time I have used clientcontext.Execute(), etc. but gone cipher.
I have tried to search on net but nothing I found there.
I then decided to look more closely the way data is being added in SharePoint list and I found something surprising element there.
After setting field values and updating the item, when I executed that code with clientcontext.Execute(),
It started adding information in list fields but not at a time what it does with Server Object Model,
It starts adding field values one by one
Let say there are 3 fields:
Title, Last name and First Name
And we have written the code snippet something list
Called the AddListInformation then
Additem[“Last name”]=”View”;
Additem[“First Name”]=”View”;
When I checked the List, I found that the written script first added one field value, updated that one then added 2nd field value and so one. And that is why workflow gets executed. For proof, I am adding two snap shots below.

No comments :

Post a Comment