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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Cancel save Event doesnot work in javascript

(0) ShareShare
ReportReport
Posted on by

Hi Guys,

I have one entity and enter the data in that entity and am using javascript for compare records in same entity either this record is available in that entity or not.while i save the record i call javascript for compare record using mobile no and email id field if the record is equal to the previous record means they show some popup with ok either you want to continue the record or you going to prevent the record save..i write the code but it is not working,after click cancel the record is save but i want to don't save the record..what i want to make change in the code...

This is my code...

function preventAutoSave(econtext) {
var eventArgs = econtext.getEventArgs();
if (eventArgs.getSaveMode() == 70) {
eventArgs.preventDefault();
} else{
compareCredit();
}
}

function compareCredit(econtext)
{
var email = Xrm.Page.getAttribute("emailaddress").getValue();
var mobile = Xrm.Page.getAttribute("new_mobileno").getValue();

if(email != null && mobile != null){
var cc_Email = email.toLowerCase().trim();
var cc_MobilePhone = mobile.replace(/ +/g, "")

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/new_creditcardsalemanagementsystems?$select=emailaddress,new_mobileno", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
for (var i = 0; i < results.value.length; i++) {
var emailaddress = results.value[i]["emailaddress"];
var resultEmail = emailaddress.toLowerCase().trim();
var mobileno = results.value[i]["new_mobileno"];
var resultMobile = mobileno.replace(/ +/g, "");

if(cc_Email == resultEmail && cc_MobilePhone == resultMobile)
{
Xrm.Utility.confirmDialog("This record has already been created, do you want to continue or cancel", function () {
Xrm.Page.data.entity.save();
},
function (econtext) {
var eventArgs = econtext.getEventArgs();
if (eventArgs.getSaveMode() == 1)
{
eventArgs.preventDefault();
Xrm.Page.getAttribute("new_email").setValue(null);
Xrm.Page.getAttribute("new_mobilephone").setValue(null);
}

});
//alert("It is in Blacklist..");
}
else if(cc_Email == resultEmail && cc_MobilePhone != resultMobile){

alert("Email ID is Match..");
}else if(cc_Email != resultEmail && cc_MobilePhone == resultMobile){

alert("Mobile No is Match..");
}
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}else{
return true;
}
}

Help me Guys...

Thank You

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    crm development Profile Picture
    870 on at

    Hi Dinesh,

    You have not passed econtext to compareCredit function. Amend the code as per mentioned below and give a try. Thanks.


     function preventAutoSave(econtext) {
     var eventArgs = econtext.getEventArgs();
     if (eventArgs.getSaveMode() == 70) {
     eventArgs.preventDefault();
     } else{
     compareCredit(econtext);
     }
    }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans