Tip #589: Programmatically Move Cross Entity Business Process Flow Stages in CRM 2016

It’s been a while since we’ve heard from Gayan “Not Daddy” Perera. As often the case with Gayan’s tips, this one is a nugget.

Moving the stage of a cross entity business process flow programmatically can be achieved by using the NavigateToNextEntity request. Most of the parameters are self explanatory, the only tricky one is the NewTraversedPath parameter (New! I knew it! We blogged about TraversedPath before and it did look promising – t.j.). This is a string value containing the previous stage id and the next stage id combined together with a comma.

Here is an example. Let’s say we have a case, the next step is to review the case email which will refer to the latest email from the customer. What we’re wanting to achieve is to automatically set this stage along with the email record reference so the user doesn’t need to click Next and then to select the Email record; eliminating two additional clicks.

OrganizationRequest or = 
   new OrganizationRequest("NavigateToNextEntity");
or.Parameters.Add("ProcessId", 
   new Guid("guid of the business process flow"));

or.Parameters.Add("NewActiveStageId", 
   new Guid("guid of the next stage"));
or.Parameters.Add("CurrentEntityLogicalName", 
   "incident");
or.Parameters.Add("CurrentEntityId", 
   new Guid("{guid of the case}"));

or.Parameters.Add("NextEntityLogicalName", 
   "email");
or.Parameters.Add("NextEntityId", 
   new Guid("{guid of the email}"));
            
or.Parameters.Add("NewTraversedPath", 
   "previous stage guid,next stage guid");

var response = sdk.Execute(or) as OrganizationResponse;

Read more at the source.

3 thoughts on “Tip #589: Programmatically Move Cross Entity Business Process Flow Stages in CRM 2016

  1. tim says:

    Thanks for this.

    Can this method be used for progressing stages within the entity.

    Since branching (traversedpath) I can’t work out how to pro grammatically progress stages in C# (I now this can be done client side but this is not suitable for us) – any help would be appreciated.

    Thanks

  2. Thiago says:

    I tried to use that code in the plugin but got this error;

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: OrganizationServiceFaultDetail:

    fbdfcdd3-c146-43ee-beaa-d9061bf41738
    -2147220891

    OperationStatus
    0

    SubErrorCode
    -2146233088

    OrganizationServiceFault
    2017-08-12T13:59:17.0883523Z
    false

    the strange thing is, when I try to run that code in console application works well, only when I try to put it in update plugin message, the I got the error

Leave a Reply

Your email address will not be published. Required fields are marked *