0

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?

2

1 Answer 1

1

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();
2
  • Thanks for the code.. but it does not contain any comment or description, so it will be hard to understand what the code is actually doing.. can u advice more?
    – John John
    Commented Jul 29, 2019 at 0:43
  • 1
    The code mean, set workflow event type to only "WorkflowStart" before update the list item, then reset the event type for the workflow.
    – LZ_MSFT
    Commented Jul 29, 2019 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.