Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Workflow 2013 does not start for the last added list item from CSOM

$
0
0

Hi,

There is the code below which starts workflow for an item. The code successfully works when item is not last in a list, but it quietly fails (StartWorkflowOnListItem is called but workflow does not start) if the item is last added. You can add an item from the web page or other way. What is it? Is it a bug?

Web web = clientContext.Web;

clientContext.Load(web);

clientContext.ExecuteQuery();

List list = clientContext.Web.Lists.GetByTitle("mmlib");

clientContext.Load(list);

clientContext.ExecuteQuery();

WorkflowServicesManager manager =newWorkflowServicesManager(clientContext, web);

clientContext.Load(manager);

clientContext.ExecuteQuery();

WorkflowSubscriptionService service = manager.GetWorkflowSubscriptionService();

clientContext.Load(service);

clientContext.ExecuteQuery();

WorkflowSubscriptionCollection wscoll = service.EnumerateSubscriptionsByList(list.Id);

clientContext.Load(wscoll);

clientContext.ExecuteQuery();

CamlQuery camlQuery =CamlQuery.CreateAllItemsQuery();

ListItemCollection listItems = list.GetItems(camlQuery);

clientContext.Load(listItems,

items => items.Include(item => item.DisplayName,item => item.Id));

clientContext.ExecuteQuery();

foreach (ListItem listItemin listItems)

{

clientContext.Load(listItem);

clientContext.ExecuteQuery();

int Id = 95;

if (listItem.Id.Equals(Id))

{

foreach (WorkflowSubscription wsin wscoll)

if (ws.Name.Equals("settitle"))

{

WorkflowInstanceService wis = manager.GetWorkflowInstanceService();

var payload =newDictionary<string,object>();

ClientResult<Guid> result = wis.StartWorkflowOnListItem(ws, listItem.Id, payload);

}

}

}

              






Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>