Question

I have a custom list inside our sharepoint online classic team site collection. and i define a workflow 2013 on the custom list. where the workflow will be executed when creating and editing the list items. i also wrote a console application which run on a schedule. where the console application will do some checking and updating the list items using client side object module code.

but inside my client side code, can i prevent the sharepoint workflow from been executed when i update the item inside my console application code?

Was it helpful?

Solution

The following CSOM C# code for your reference.

Web web = context.Web;
var list=web.Lists.GetByTitle("CustomList");
context.Load(list);
context.ExecuteQuery();
var workflowServicesManager = new WorkflowServicesManager(context, context.Web);
var workflowSubscriptionService = workflowServicesManager.GetWorkflowSubscriptionService();
// get all workflow associations
var workflowAssociations = workflowSubscriptionService.EnumerateSubscriptionsByList(list.Id);
context.Load(workflowAssociations);
context.ExecuteQuery();
var wf = workflowAssociations[0];
List<string> eventTypes = new List<string>() { "WorkflowStart" };
wf.EventTypes = eventTypes;
workflowSubscriptionService.PublishSubscriptionForList(wf, list.Id);                
var listitem = list.GetItemById(1);
listitem["Title"] = DateTime.Now.ToString();
listitem.SystemUpdate();
context.ExecuteQuery();
eventTypes = new List<string>() { "WorkflowStart", "ItemUpdated" };//ItemUpdated
wf.EventTypes = eventTypes;
workflowSubscriptionService.PublishSubscriptionForList(wf, list.Id);
context.ExecuteQuery();
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top