web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Prevent Default is not working in JavaScript while Project Stage Change

(0) ShareShare
ReportReport
Posted on by 277

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);
}

);


}


}

  • Suggested answer
    Matthew Lazowski Profile Picture
    3,163 on at

    Hi Ashik, could you explain without code what you want to achieve? Matthew

    P.S.

    Also you need to use these APIs to work with msdyn_project entity:

    docs.microsoft.com/.../schedule-api-preview

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 274 Super User 2026 Season 2

#2
Aayush Tiwari Profile Picture

Aayush Tiwari 213

#3
Subra Profile Picture

Subra 202 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans