Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Prevent Default is not working in JavaScript while Project Stage Change

Posted on by 267

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
    Matthew Lazowski 3,163 on at
    RE: Prevent Default is not working in JavaScript while Project Stage Change

    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

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans