Automatically Navigate to new stage to Cross Entity of Business Process Flow

Standard

Business Process Flow is a great feature help to guide user step by step to carry out their work quickly. It has been supported for a lot API for interacting with it from version 2015.

But in some case, we want to navigate new stages automatically in cross process flow, in fact, it is not recommended by Microsoft because BPF is a feature for users to interact with CRM

BP1

How can Do it in JavaScript?

In fact, MS CRM raised a request to change stage of BPF when user click on the Next Stage but it is not public API for developers.

This following function will excute the “NavigateToNextEntity” request to change to new stage automatically.

function navigateToNextStage(processId, nextActiveStageId, currentEntName, currentEntId,
nextEntName, nextEntId, traverPath)

{

    //debugger;

    var serverUrl = Xrm.Page.context.getClientUrl();

    serverUrl += “/XRMServices/2011/Organization.svc/web”;

    var requestXML = “<s:Envelope xmlns:s=\”http://schemas.xmlsoap.org/soap/envelope/\”>”;

    requestXML += “<s:Body>”;

    requestXML += “<Execute
xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts/Services\” xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”>”
;

    requestXML += “<request
xmlns:a=\”http://schemas.microsoft.com/xrm/2011/Contracts\”>”
;

    requestXML += “<a:Parameters
xmlns:b=\”http://schemas.datacontract.org/2004/07/System.Collections.Generic\”>”
;

 

    requestXML += “<a:KeyValuePairOfstringanyType>”;

    requestXML += “<b:key>ProcessId</b:key>”

    requestXML += “<b:value i:type=\”c:guid\” xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/\”>” +
processId + 
“</b:value>”;

    requestXML += “</a:KeyValuePairOfstringanyType>”; 

 

    requestXML += “<a:KeyValuePairOfstringanyType>”;

    requestXML += “<b:key>NewActiveStageId</b:key>”;

    requestXML += “<b:value i:type=\”c:guid\”
xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/\”>”
+
nextActiveStageId +
“</b:value>”;

    requestXML += “</a:KeyValuePairOfstringanyType>”;

 

    requestXML += “<a:KeyValuePairOfstringanyType>”;

    requestXML += “<b:key>CurrentEntityLogicalName</b:key>”;

    requestXML += “<b:value
i:type=\”c:string\” xmlns:c=\”http://www.w3.org/2001/XMLSchema\”>”
+
currentEntName +
“</b:value>”;

    requestXML += “</a:KeyValuePairOfstringanyType>”;

 

    requestXML += “<a:KeyValuePairOfstringanyType>”;

    requestXML += “<b:key>CurrentEntityId</b:key>”;

    requestXML += “<b:value i:type=\”c:guid\”
xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/\”>”

+currentEntId +
“</b:value>”;

    requestXML += “</a:KeyValuePairOfstringanyType>”;

 

 

    requestXML += “<a:KeyValuePairOfstringanyType>”;

    requestXML += “<b:key>NextEntityLogicalName</b:key>”;

    requestXML += “<b:value
i:type=\”c:string\” xmlns:c=\”http://www.w3.org/2001/XMLSchema\”>”
+
nextEntName +
“</b:value>”;

    requestXML += “</a:KeyValuePairOfstringanyType>”;

 

    requestXML += “<a:KeyValuePairOfstringanyType>”;

    requestXML += “<b:key>NextEntityId</b:key>”;

    requestXML += “<b:value
i:type=\”c:guid\” xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/\”>”
+
nextEntId +
“</b:value>”

    requestXML += “</a:KeyValuePairOfstringanyType>”;

 

    requestXML += “<a:KeyValuePairOfstringanyType>”;

    requestXML += “<b:key>NewTraversedPath</b:key>”;

    requestXML += “<b:value
i:type=\”c:string\” xmlns:c=\”http://www.w3.org/2001/XMLSchema\”>”
+ traverPath + “</b:value>”;

    requestXML += “</a:KeyValuePairOfstringanyType>”;

 

    requestXML += “</a:Parameters>”;

    requestXML += “<a:RequestId i:nil=\”true\” />”;

    requestXML += “<a:RequestName>NavigateToNextEntity</a:RequestName>”;

    requestXML += “</request>”;

    requestXML += “</Execute>”;

    requestXML += “</s:Body>”;

    requestXML += “</s:Envelope>”;

 

    var req = new XMLHttpRequest();

    req.open(“POST”, serverUrl, false);

    req.setRequestHeader(“Accept”, “application/xml, text/xml, */*”);

    req.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);

    req.setRequestHeader(“SOAPAction”, http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute&#8221;);

    req.send(requestXML);

    //console.log(“Request”,
req);

    var response = req.responseXML;

 

    //Xrm.Utility.openEntityForm(nextEntName, nextEntId);

 

    //console.log(“Null”,
response);

}

Note that “traverPath” parameter is a string of Guid Id of Old stage and new stage, it was separated by comma like that  ‘340a043b-95c2-c042-e815-38d605d7abcb, ca590f62-0565-4a6d-ae04-d68d39b2b2d9’ .

Hope that it will be useful for someone.

3 thoughts on “Automatically Navigate to new stage to Cross Entity of Business Process Flow

  1. Hi, Instead of choosing a record in BPF(while moving to next stage) what if i click on create record on the BPF. How to handle that ? please provide me your thougts

    Like

  2. Hi Vardhan,

    Thank you for your visit my blog. I am sorry for lately reply.

    If you move to next stage of Cross Entity in BPF, it will show you the dialog for selecting the entity record, if you create new one, it will also associate new record with current record that you are working.

    If you want o handle this automatically, you can create by your code (javascript or your custom business), you can disable the Next button if you want to automatically stage moving in BPF.

    Regards

    Like

Leave a comment