Hi,
I have a requirement where I have to update the Business Process Flow real-time on changing field status selected by the user.
The same requirement I have achieved on Opportunity entity BPF (custom BPF) and working fine. but I am getting an issue when the BPF stage moves from Lead to Opportunity after Lead qualification.

Error Status 500:
Javascript
if (optionText == "Bid Process") { //Checking option in which BPF stage will move
if (getActiveProcess.toUpperCase() == "919E14D1-6489-4852-ABD0-A63A6ECAAC5D") //checking Lead to Opportunity BPF
{
var Stage2 = "3A275C22-FC45-4E89-97FC-41E5EC578743"; // Stage ID
var entity = {};
entity["activestageid@odata.bind"] = "/processstages(" + Stage2 + ")";
entity["traversedpath"] = stageId + ", " + Stage2; // StageId is the active stage ID calling dynamically
var req = new XMLHttpRequest();
req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/leadtoopportunitysalesprocesses(" + currentBPFInstanceID + ") ", true); // here currentBPFInstanceID is process InstanceId and calling dynamically.
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
//Success – No Return Data – Do Something
//alert("Success");
} else {
alert("Error");
//Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
}