Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

prevent default not working

Posted on by 267

Hello Team,

below  my code prevent default is not working can you suggest me anything is missing here?

function preStageChange(executionContext) {

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 stopSave=false;
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);
}

);


}

}

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans