Start workflow programatically in SharePoint 2013

I had a business requirement where I need to start SharePoint 2013 workflow on demand. We have a form to validate some data on a list item before starting the workflow. When user click on continue button of validation form it first validate all field, once it is validated it will trigger a workflow associated with the list

Below is the code example on how to start SharePoint 2013 workflow programatically.

var workflowServiceManager = new WorkflowServicesManager(web);

var workflowSubscriptionService = workflowServiceManager.GetWorkflowSubscriptionService();

//Get all workflows associated with a list

var subscriptions = workflowSubscriptionService.EnumerateSubscriptionsByList(listId);

//Run all workflows associated with the list

foreach (var workflowSubscription in subscriptions)

{    

 var inputParameters = new Dictionary<string, object>();    

 inputParameters.Add("MyProperty", "MyValue"); 

workflowServiceManager.GetWorkflowInstanceService().StartWorkflowOnListItem(workflowSubscription, itemId, inputParameters);
Blogs

See More Articles

Contact us

To begin your digital transformation, get in touch.

We’re pleased to address any inquiries you might have and assist you in selecting the service that best suits your requirements.

Your benefits:
Speak To Us