Get Workflow ID and Execute it in CRM 2011, 2013 and 2015 using C# Code

Here is the code for retrieving workflow id by name and issue execute request on it.

QueryExpression objQueryExpression = new QueryExpression(“workflow”);
objQueryExpression.ColumnSet = new ColumnSet(true);
objQueryExpression.Criteria.AddCondition(new ConditionExpression(“name”, ConditionOperator.Equal, “”));
objQueryExpression.Criteria.AddCondition(new ConditionExpression(“parentworkflowid”, ConditionOperator.Null));
EntityCollection entColWorkflows = service.RetrieveMultiple(objQueryExpression);
if (entColWorkflows != null && entColWorkflows.Entities.Count > 0)
{
       ExecuteWorkflowRequest request = new ExecuteWorkflowRequest()
       {
            WorkflowId = entColWorkflows.Entities[0].Id,
            EntityId = guidRecord
       };
       // Execute the workflow.
       ExecuteWorkflowResponse response = (ExecuteWorkflowResponse)service.Execute(request);
}


Happy CRM’img
Gopinath.
 

2 thoughts on “Get Workflow ID and Execute it in CRM 2011, 2013 and 2015 using C# Code

  1. Sabih Khan February 12, 2017 / 12:52 pm

    Brother i am getting the response guid as all 0's does this shows that my workflow has executed ?

    Like

  2. Blogger May 8, 2018 / 10:23 am

    it it possible to trigger workflow without \”EntityId = guidRecord\”

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s