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, "<WorkflowName>"));
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.
QueryExpression objQueryExpression = new QueryExpression("workflow");
objQueryExpression.ColumnSet = new ColumnSet(true);
objQueryExpression.Criteria.AddCondition(new ConditionExpression("name", ConditionOperator.Equal, "<WorkflowName>"));
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.
Brother i am getting the response guid as all 0's does this shows that my workflow has executed ?
ReplyDeleteit it possible to trigger workflow without "EntityId = guidRecord"
ReplyDeletenice.....!
ReplyDeleteui path training