Friday 4 November 2011

Selecting the correct workflowid

A very quick one, which is mostly an aide-memoire for myself, but others may find useful.

I occasionally need to run CRM workflows programmatically using an ExecuteWorkflow request. This takes a workflowid as a parameter, but the question is, which one ? If you look at the workflow entity, you'll find several records for a workflow with a given name. The logic I use to determine which is the correct on is:


  • statecode = 1 (Activated)

  • activeworkflowid is not null

But use the workflowid value of the record for which activeworkflowid is not null. This seems a but counter-intuitive to me, hence this post

2 comments:

Naim said...

You need to use the Type field to identify if the workflow instance is of type Definition.

See the WorkflowType Class in the CRM SDK.

Regards
Naim

David Cabaniuk said...

Could you not open the workflow up in the CRM interface and view its URL parameters for id. The Guid against that id is the workflow id.