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 :
Microsoft Dynamics CRM (Archived)

Script Error While call Javascript

(0) ShareShare
ReportReport
Posted on by

Hi Guys,

I created one javascript for compare records in dynamics crm..but while call the function it always show the error..and Javascript webresource is doesn't shows in the browser developer tools..i don't know why this error occur

This is my Error am facing all time

1234.error1.png

and this is my code..

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

if(email != null && mobile != null){

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(email == resultEmail && mobile == resultMobile)
{
alert("It is in Blacklist..");
}else if(email != resultEmail && mobile == resultMobile){

alert("mobile no is Match..");
}else if(email == resultEmail && mobile != resultMobile){

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

*This post is locked for comments

  • Verified answer
    Rawish Kumar Profile Picture
    13,758 on at

    Hi there,

    the line

          var mobileno = results.value[i].["new_mobileno"];

    should be

          var mobileno = results.value[i]["new_mobileno"];   //no need of a "."

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi,

    Try with this  -

    function compareCredit() {
        var email = Xrm.Page.getAttribute("emailaddress").getValue();
        email = email.toLowerCase();
        var mobile = Xrm.Page.getAttribute("new_mobileno").getValue();
        var isEmailMatch = false;
        var isMobileMatch = false;
        if (email != null && mobile != null) {
            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 ((email == resultEmail) && (isEmailMatch == false)) {
                                isEmailMatch = true;
                            }
                            if ((mobile == resultMobile) && (isMobileMatch == false)) {
                                isMobileMatch = true;
                            }
    
                        }
                        if (isEmailMatch == true) {
                            alert("Email Id is Match..");
                        }
                        else {
                            alert("Does not match Email")
                        }
    
                        if (isMobileMatch == true) {
                            alert("mobile no is Match..");
                        }
                        else {
                            alert("Does not match mobile ")
                        }
    
                    } else {
                        Xrm.Utility.alertDialog(this.statusText);
                    }
                }
            };
            req.send();
        } 
    }


  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Dinesh,

    The error <methodname> is not defined at eval is mainly occurred for 2 reason-

    1) If there is any syntax error in your JavaScript file because of which CRM failed to load the JavaScript.

    2) You have added a new method in your file and uploaded but the browser Is still referencing the older version.

    In your case, it doesn't look like a syntax issue (unless you have some other code in your js file). It looks more like a caching issue.

    Publish all customization, refresh browser and if possible try in cognito/ in private mode.

    Hope this helps.

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 > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans