Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Workflow must be in Published state." when trying to execute a CRM 2011 Workflow

I need to execute a CRM 2011 workflow from .Net. I have looked at the CRM 2011 SDK example which uses the ExecuteWorkflowRequest message. The example works which is a good start, but the sample also creates the CRM Workflow item that it then executes.

I am trying to execute a workflow item that already exists. But I keep on getting a error "Workflow must be in Published state." even though I have Activiated the workflow.

I have tried executed the same workflow item it with the CRM 4.0 SDK and it executes fine. But I can't use this SDK with the way the system works as I need to execute a workflow item form a custom code workflow activity.

Thanks in advance

like image 537
user716896 Avatar asked Apr 20 '11 10:04

user716896


People also ask

What is Workflow in CRM Dynamics?

Workflows automate business processes without a user interface. People usually use workflow processes to initiate automation that doesn't require any user interaction. Each workflow process is associated with a single entity.

Is workflow deprecated?

At the end of 2022, Salesforce will be retiring Workflow Rules and Process Builder automation. While your current Workflow Rules and Process Builders will continue to run, you will not be able to create new automation using these tools. Instead, you'll have to create new automation using Flow.


1 Answers

For each workflow created there are two workflow entities stored in CRM 2011 database. The workflow entity has an attribute titled 'Type'. Type == 1 is published. Type == 2 is draft. When you query for the workflow, be sure to specify the Type value in your where clause.

var workflow = context.CreateQuery("workflow").FirstOrDefault(w =>
w.GetAttributeValue<int>("type") == 1 &&
w.GetAttributeValue<string>("name") == workflowName &&
w.GetAttributeValue<bool>("ondemand") == true &&
w.GetAttributeValue<string>("primaryentity") == targetEntityName);

Refer to the CRM 2011 SDK sample code for examples how to connect to the Organization service.

like image 90
Brad Flood Avatar answered Nov 03 '22 01:11

Brad Flood