Hello Team,
Below of my code Prevent Default is not working can you suggest me what is missing here?
function form_onLoad(executionContext){
var formContext = executionContext.getFormContext();
formContext.data.process.addOnPreStageChange(preStageChange);
}
function preStageChange(executionContext) {
var formContext = executionContext.getFormContext();
debugger;
var globalContext = Xrm.Utility.getGlobalContext();
var direction = executionContext.getEventArgs().getDirection();
var projectId = Xrm.Page.data.entity.getId();
projectId = projectId.replace('{', '');
projectId = projectId.replace('}', '');
var activeStageId, activeStageName;
//Get the current active stage of the process
var activeStage = Xrm.Page.data.process.getActiveStage();
//Get the ID of the current stage
activeStageId = activeStage.getId();
//Get the Name of the current stage
activeStageName = activeStage.getName();
if (activeStageName == "Plan" && direction == "Next") {
Xrm.WebApi.online.retrieveMultipleRecords("salesorderdetail", "?$select=_salesorderid_value,msdyn_orderlinenumber&$filter=_msdyn_project_value eq " + projectId + " and msdyn_billingmethod eq " + 192350001 + "").then(
function success(result) {
if (result.entities.length > 0) {
var orderLine = result.entities[0];
var msdyn_orderlinenumber = orderLine["msdyn_orderlinenumber"];
var salesorderid = new Array();
salesorderid[0] = new Object();
salesorderid[0].id = orderLine["_salesorderid_value"];
salesorderid[0].name = orderLine["_salesorderid_value@OData.Community.Display.V1.FormattedValue"];
if (salesorderid[0].name != null && msdyn_orderlinenumber != null) {
alert(msdyn_orderlinenumber);
Xrm.WebApi.online.retrieveMultipleRecords("msdyn_contractlinescheduleofvalue", "?$select=msdyn_contractlinelineid&$filter=msdyn_contractlinelineid eq '+msdyn_orderlinenumber+'").then(
function success(result) {
if (result.entities.length > 0) {
alert("Record Found");
return;
} else {
alert("Record Not Found");
executionContext.getEventArgs().preventDefault();
Xrm.Utility.alertDialog("Next Stage is not allowed");
return;
}
},
function(error) {
console.log(error.message);
}
);
}
}
},
function(error) {
console.log(error.message);
}
);
}
}