web
You’re offline. This is a read only version of the page.
close
Skip to main content
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

I have the same question (0)
  • Verified answer
    Rawish Kumar Profile Picture
    13,758 on at
    RE: Script Error While call Javascript

    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
    RE: Script Error While call Javascript

    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
    RE: Script Error While call Javascript

    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

Responsible AI policies

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

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
UllrSki Profile Picture

UllrSki 2

#3
SC-08081331-0 Profile Picture

SC-08081331-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans