I want to cancel saving process if the new_name is existing in the current entity.
Here's what i have tried:
function preventsave(context){
var login_name = Xrm.Page.getAttribute("new_name").getValue();
var Entity = "new_parentrecord";
var Select = "?$select=new_name";
var Filter = "&$filter=new_name eq '" login_name "'";
var saveEvent = context.getEventArgs();
//alert(login_name);
Xrm.WebApi.retrieveMultipleRecords(Entity, Select Filter).then(
function success(result) {
alert("Login Name Exist !!");
if (result.entities[0].new_name !== null) {
SetPageNotification("Login Name Exist !", "INFO", "InfoNotification");
saveEvent.preventDefault(); //1st prevent
}
},
function (error) {
console.log(error.message);
}
);
saveEvent.preventDefault(); //2nd prevent
}
function SetPageNotification(aMessage, aType, aNotificationName) {
Xrm.Page.ui.setFormNotification(
aMessage,
aType,
aNotificationName
);
}
function ClearAllNotifications() {
ClearPageNotification("InfoNotification");
}
after trial and error i noticed that the 1st prevent is not working. but the 2nd prevent is working. Can you help me to make the 1st prevent to work ?