locked
Call a workflow from code - CRM 2011 RRS feed

  • 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

    Wednesday, August 17, 2011 1:48 PM
    Moderator
  • 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

    Wednesday, August 17, 2011 1:30 PM
    Moderator
  • 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"

    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

    Wednesday, August 17, 2011 1:30 PM
    Moderator
  • 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

    Wednesday, August 17, 2011 1:48 PM
    Moderator
  • You can also discover the GUID identifier of a Workflow (or indeed, most any entity instance) by:

    1. Open the entity record form
    2. Click on the Actions menu
    3. Click on copy link
    4. 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.com
    Thursday, 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"

    Thursday, May 17, 2012 9:11 AM