workflow execution from Plugin

Here is quick sample code for workflow execution from Plugin …

Execute workflow …

        /// <summary>
        /// Execute porcess
        /// </summary>
        /// <param name="entityId"></param>
        /// <param name="service"></param>
        /// <param name="workflowId"></param>
        private static void ExecuteProcess(IOrganizationService service, Guid entityId, Guid workflowId)
            ExecuteWorkflowRequest request = new ExecuteWorkflowRequest()

                WorkflowId = workflowId,

                EntityId = entityId


            // Execute the workflow.
            ExecuteWorkflowResponse response = (ExecuteWorkflowResponse)service.Execute(request);

Get the Workflow/Process…

        /// <summary>
        /// Get Porcess by name
        /// </summary>
        /// <param name="service"></param>
        /// <param name="processName"></param>
        /// <returns></returns>
        private static EntityCollection GetProcess(IOrganizationService service, string processName)

            // Instantiate QueryExpression QEworkflow
            var qeWorkflow = new QueryExpression("workflow");

            // Add columns to QEworkflow.ColumnSet
            qeWorkflow.ColumnSet.AddColumns("workflowid", "name", "category", "primaryentity", "type");
            qeWorkflow.AddOrder("name", OrderType.Ascending);

            // Define filter QEworkflow.Criteria
            qeWorkflow.Criteria.AddCondition("statecode", ConditionOperator.Equal, 1);
            qeWorkflow.Criteria.AddCondition("type", ConditionOperator.Equal, 1);
            qeWorkflow.Criteria.AddCondition("rendererobjecttypecode", ConditionOperator.Null);
            qeWorkflow.Criteria.AddCondition("category", ConditionOperator.Equal, 0);
            qeWorkflow.Criteria.AddCondition("primaryentity", ConditionOperator.Equal, 112);
            qeWorkflow.Criteria.AddCondition("name", ConditionOperator.Equal, processName);

            EntityCollection workflows = service.RetrieveMultiple(qeWorkflow);
            return workflows;



Thank you!

Leave a Reply

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

You are commenting using your 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