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

3

5

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

Forte answered 20/4, 2011 at 10:6 Comment(0)
A
15

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.

Amorphous answered 10/5, 2011 at 23:18 Comment(2)
Is this still correct? I noticed that Type in my case has three possible values (1 = Definition; 2 = Activation; 3 = Template). More information can be found in the answer to a question by Michael B.Scott as seen hereZadazadack
Additionally to my earlier comment. The workflow entity has a componentstate attribute which contains a value indicating if the component is (published = 0, unpublished = 1, deleted = 2 or deleted unpublished = 3).Zadazadack
N
0

Without have created any Workflows, if you are getting an error that says "Workflow must be in Published state", then have you tried to 'publish all customizations' to see if that helps?

To do this, click 'Settings->Solutions->Publish all Customizations'.

Nakamura answered 21/4, 2011 at 0:2 Comment(0)
B
0

For my case, my workflow was saved as Process Template.Changing it to Process should solve the problem.

enter image description here

Brachium answered 30/1, 2019 at 22:26 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.