Answered by:
Call a workflow from code - CRM 2011

Question
-
Hi,
Is it possible to call an existing workflow programmaticaly in CRM 2011 online?
Wednesday, August 17, 2011 1:21 PM
Answers
-
If you are in CRM Online you would have to retrieve all your workflows and see which is the one you need:
Guid workflowId; QueryExpression query = new QueryExpression(Workflow.EntityLogicalName); query.ColumnSet = new ColumnSet("name"); EntityCollection coll = service.RetrieveMultiple(query); foreach (Entity e in coll.Entities) { if (((string)e["name"]).Equals("your workflow title")) { workflowId = e.Id; } }
Gonzalo | gonzaloruizcrm.blogspot.com
- Proposed as answer by Gonzalo Ruiz RModerator Wednesday, August 17, 2011 1:48 PM
- Marked as answer by Jamie MileyModerator Thursday, May 17, 2012 2:36 PM
Wednesday, August 17, 2011 1:48 PMModerator -
You can execute workflows explicitely if they have been defined as on-demand. You can use this code:
ExecuteWorkflowRequest request = new ExecuteWorkflowRequest { WorkflowId = workflowId, EntityId = entityId, }; service.Execute(request);
Gonzalo | gonzaloruizcrm.blogspot.com
- Proposed as answer by Gonzalo Ruiz RModerator Wednesday, August 17, 2011 1:30 PM
- Marked as answer by Jamie MileyModerator Thursday, May 17, 2012 2:36 PM
Wednesday, August 17, 2011 1:30 PMModerator -
You need to generate the Xrm.cs file using the crmsvctool to get a library of all the entity classes. You can then use stongly typed name like EntityName.EntityLogicalName.
In the current scenario you can simply replace this with workflow which is schema name of the Workflow entity.
HTH
Sam
Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"
- Marked as answer by Jamie MileyModerator Thursday, May 17, 2012 2:37 PM
Thursday, May 17, 2012 9:11 AM
All replies
-
You can execute workflows explicitely if they have been defined as on-demand. You can use this code:
ExecuteWorkflowRequest request = new ExecuteWorkflowRequest { WorkflowId = workflowId, EntityId = entityId, }; service.Execute(request);
Gonzalo | gonzaloruizcrm.blogspot.com
- Proposed as answer by Gonzalo Ruiz RModerator Wednesday, August 17, 2011 1:30 PM
- Marked as answer by Jamie MileyModerator Thursday, May 17, 2012 2:36 PM
Wednesday, August 17, 2011 1:30 PMModerator -
How can I know my workflowID?Wednesday, August 17, 2011 1:38 PM
-
If you are in CRM Online you would have to retrieve all your workflows and see which is the one you need:
Guid workflowId; QueryExpression query = new QueryExpression(Workflow.EntityLogicalName); query.ColumnSet = new ColumnSet("name"); EntityCollection coll = service.RetrieveMultiple(query); foreach (Entity e in coll.Entities) { if (((string)e["name"]).Equals("your workflow title")) { workflowId = e.Id; } }
Gonzalo | gonzaloruizcrm.blogspot.com
- Proposed as answer by Gonzalo Ruiz RModerator Wednesday, August 17, 2011 1:48 PM
- Marked as answer by Jamie MileyModerator Thursday, May 17, 2012 2:36 PM
Wednesday, August 17, 2011 1:48 PMModerator -
You can also discover the GUID identifier of a Workflow (or indeed, most any entity instance) by:
- Open the entity record form
- Click on the Actions menu
- Click on copy link
- Paste it somewhere
The link will look something like:
https://crminternal.mrcrm.com.au:444/MrCRM/sfa/workflow/edit.aspx?id=%7b74AD0E4B-299F-4F31-82BF-792BDB9E178E%7d
where the GUID identifier is the portion in bold.
--pogo (pat) @ pogo69.wordpress.comThursday, August 18, 2011 12:53 AM -
hi,
thanks for your solution.
How can you write "Workflow.EntityLogicalName"?
Wednesday, May 16, 2012 8:32 AM -
You need to generate the Xrm.cs file using the crmsvctool to get a library of all the entity classes. You can then use stongly typed name like EntityName.EntityLogicalName.
In the current scenario you can simply replace this with workflow which is schema name of the Workflow entity.
HTH
Sam
Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"
- Marked as answer by Jamie MileyModerator Thursday, May 17, 2012 2:37 PM
Thursday, May 17, 2012 9:11 AM