Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

I am getting script error like -------- "GetAddress is not defined at eval (eval at RunHandlerInternal (https://info8.crm8.dynamics.com/form/ClientApiWrapper.aspx?ver=-1047458540:153:1), <anonymous>:1:1)"

Posted on by 95

HI Everyone

Business scenario :  I created a custom field Get address Check box  in Contact form,

when check box is checked i need get the address of selected account id and to display that in contact address.

for this i wrote javascript which fires when checkbox is checcked.

Javascript : 

function GetAddress() {
if (Xrm.Page.getControl("parentcustomerid") != null) {
if (Xrm.Page.getAttribute("parentcustomerid").getValue() != null && Xrm.Page.getAttribute("parentcustomerid").getValue()[0].id != null) {
var customerId = Xrm.Page.getAttribute("parentcustomerid").getValue()[0].id;
var customerType = Xrm.Page.getAttribute("parentcustomerid").getValue()[0].entityType;
var serverUrl = Xrm.Page.context.getServerUrl();
if (customerType == "account") {
var retrievestring = serverUrl + "/xrmservices/2011/OrganizationData.svc/AccountSet?$filter=AccountId eq(guid'" + parentcustomerid+ "')";
var recordinfo = Retrieve(retrievestring);
if (recordinfo != null) {
var accountAddressAttributes = [recordinfo.results[0].Address1_Name, recordinfo.results[0].Address1_Line1, recordinfo.results[0].Address1_Line2,
recordinfo.results[0].Address1_Line3, recordinfo.results[0].Address1_City, recordinfo.results[0].Address1_StateOrProvince, recordinfo.results[0].Address1_Country,
recordinfo.results[0].Address1_Telephone1, recordinfo.results[0].Address1_PostalCode, recordinfo.results[0].new_District, recordinfo.results[0].new_Landmark];
Xrm.Page.getAttribute("address1_line1").setValue(recordinfo.results[0].Address1_Line1);
Xrm.Page.getAttribute("address1_line2").setValue(recordinfo.results[0].Address1_Line2);
Xrm.Page.getAttribute("address1_line3").setValue(recordinfo.results[0].Address1_Line3);
Xrm.Page.getAttribute("address1_city").setValue(recordinfo.results[0].Address1_City);
Xrm.Page.getAttribute("address1_stateorprovince").setValue(recordinfo.results[0].Address1_StateOrProvince);
Xrm.Page.getAttribute("address1_country").setValue(recordinfo.results[0].Address1_Country);
Xrm.Page.getAttribute("address1_postalcode").setValue(recordinfo.results[0].Address1_PostalCode);
Xrm.Page.data.entity.save();
Reply

}

I am getting Following script error

Untitledkjnksnldslkmwelmde.png

*This post is locked for comments

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: I am getting script error like -------- "GetAddress is not defined at eval (eval at RunHandlerInternal (https://info8.crm8.dynamics.com/form/ClientApiWrapper.aspx?ver=-1047458540:153:1), <anonymous>:1:1)"

    Hi Sreekanth,

    Can you try this and see if this works for you?

    --------------------------

    function GetAddress() {

       var accountRef = Xrm.Page.getAttribute("parentcustomerid").getValue();

       if (accountRef != null) {

           var accountId = accountRef[0].id.replace("{", "").replace("}", "");

           var req = new XMLHttpRequest();

           req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts(" + accountId + ")?$select=address1_city,address1_country,address1_line1,address1_line2,address1_line3,address1_postalcode,address1_stateorprovince", 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 result = JSON.parse(this.response);

                       var addressText = "";

                       if (result["address1_line1"] != null) {

                           addressText += result["address1_line1"] + "\n";

                           Xrm.Page.getAttribute("address1_line1").setValue(result["address1_line1"]);

                       }

                       if (result["address1_line2"] != null) {

                           addressText += result["address1_line2"] + "\n";

                           Xrm.Page.getAttribute("address1_line2").setValue(result["address1_line2"]);

                       }

                       if (result["address1_line3"] != null) {

                           addressText += result["address1_line3"] + "\n";

                           Xrm.Page.getAttribute("address1_line3").setValue(result["address1_line3"]);

                       }

                       if (result["address1_city"] != null) {

                           addressText += result["address1_city"] + "\n";

                           Xrm.Page.getAttribute("address1_city").setValue(result["address1_city"]);

                       }

                       if (result["address1_stateorprovince"] != null) {

                           addressText += result["address1_stateorprovince"] + "\n";

                           Xrm.Page.getAttribute("address1_stateorprovince").setValue(result["address1_stateorprovince"]);

                       }

                       if (result["address1_postalcode"] != null) {

                           addressText += result["address1_postalcode"] + "\n";

                           Xrm.Page.getAttribute("address1_postalcode").setValue(result["address1_postalcode"]);

                       }

                       if (result["address1_country"] != null) {

                           addressText += result["address1_country"]

                           Xrm.Page.getAttribute("address1_country").setValue(result["address1_country"]);

                       }

                       if (addressText != "") {

                           Xrm.Page.getAttribute("address1_composite").setValue(addressText);

                       }

                   } else {

                       Xrm.Utility.alertDialog(this.statusText);

                   }

               }

           };

           req.send();

       }

    }

    -------------------------------------

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: I am getting script error like -------- "GetAddress is not defined at eval (eval at RunHandlerInternal (https://info8.crm8.dynamics.com/form/ClientApiWrapper.aspx?ver=-1047458540:153:1), <anonymous>:1:1)"

    Hi Sreekanth,

    Please try the code below.

    function GetAddress() {
        var accountId = Xrm.Page.getAttribute("parentcustomerid").getValue()[0].id;
        var serverUrl = Xrm.Page.context.getServerUrl();
        var retrievestring = serverUrl + "/xrmservices/2011/OrganizationData.svc/AccountSet?$filter=AccountId eq(guid'" + accountId + "')";
        var recordinfo = Retrieve(retrievestring);
        var copyAccountAddress = Xrm.Page.getAttribute("new_copyaccountaddress").getValue();
        if (copyAccountAddress == true) {
            if (recordinfo != null) {
                var accountAddressAttributes = [recordinfo.results[0].Address1_Name, recordinfo.results[0].Address1_Line1, recordinfo.results[0].Address1_Line2,
                recordinfo.results[0].Address1_Line3, recordinfo.results[0].Address1_City, recordinfo.results[0].Address1_StateOrProvince, recordinfo.results[0].Address1_Country,
                recordinfo.results[0].Address1_Telephone1, recordinfo.results[0].Address1_PostalCode, recordinfo.results[0].new_District, recordinfo.results[0].new_Landmark];
                Xrm.Page.getAttribute("address1_line1").setValue(recordinfo.results[0].Address1_Line1);
                Xrm.Page.getAttribute("address1_line2").setValue(recordinfo.results[0].Address1_Line2);
                Xrm.Page.getAttribute("address1_line3").setValue(recordinfo.results[0].Address1_Line3);
                Xrm.Page.getAttribute("address1_city").setValue(recordinfo.results[0].Address1_City);
                Xrm.Page.getAttribute("address1_stateorprovince").setValue(recordinfo.results[0].Address1_StateOrProvince);
                Xrm.Page.getAttribute("address1_country").setValue(recordinfo.results[0].Address1_Country);
                Xrm.Page.getAttribute("address1_postalcode").setValue(recordinfo.results[0].Address1_PostalCode);
                Xrm.Page.data.entity.save();
            }
        }
    }

    Hope this helps.

  • Sreeekanth Profile Picture
    Sreeekanth 95 on at
    RE: I am getting script error like -------- "GetAddress is not defined at eval (eval at RunHandlerInternal (https://info8.crm8.dynamics.com/form/ClientApiWrapper.aspx?ver=-1047458540:153:1), <anonymous>:1:1)"

    Hii Ravi

    Thanks for your response. It's working fine .

    But my need is

    I had check box(Copy Account Address) on contact form ,if checkbox is checked i want to display it in address1_composite Field.

    I am am running this script on Onchange event of Checkbox field.

    address1_composite field getting values but its not showing on form.when we click on composite filed values are assigned to inside fields(address1_line1,address1_line2,address1_line1,address1_country)  but it's not showing on form.

    but if we click Done in composite It's getting Value

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: I am getting script error like -------- "GetAddress is not defined at eval (eval at RunHandlerInternal (https://info8.crm8.dynamics.com/form/ClientApiWrapper.aspx?ver=-1047458540:153:1), <anonymous>:1:1)"

    Hi Sreekanth,

    You are also using getServerUrl which is now deprecated, instead you should use getClientUrl.

    Also, it appears that you need to populate address from account entity to contact. I would suggest you to download CRM Rest Builder tool and use it. With this tool, you can generate similar scripts very easily and can also see the results on demand.  

    github.com/.../CRMRESTBuilder

    Below is the code I generated from this tool [using WebAPI] to populate the address details from the account entity to contact.

    -------------------------------------

    function GetAddress() {

       var accountRef = Xrm.Page.getAttribute("parentcustomerid").getValue();

       if (accountRef != null) {

           var accountId = accountRef[0].id.replace("{", "").replace("}", "");

           var req = new XMLHttpRequest();

           req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts(" + accountId + ")?$select=address1_city,address1_country,address1_line1,address1_line2,address1_line3,address1_postalcode,address1_stateorprovince", 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 result = JSON.parse(this.response);

                       Xrm.Page.getAttribute("address1_line1").setValue(result["address1_line1"]);

                       Xrm.Page.getAttribute("address1_line2").setValue(result["address1_line2"]);

                       Xrm.Page.getAttribute("address1_line3").setValue(result["address1_line3"]);

                       Xrm.Page.getAttribute("address1_city").setValue(result["address1_city"]);

                       Xrm.Page.getAttribute("address1_stateorprovince").setValue(result["address1_stateorprovince"]);

                       Xrm.Page.getAttribute("address1_country").setValue(result["address1_country"]);

                       Xrm.Page.getAttribute("address1_postalcode").setValue(result["address1_postalcode"]);

                   } else {

                       Xrm.Utility.alertDialog(this.statusText);

                   }

               }

           };

           req.send();

       }

    }

    -------------------------------------

    Hope this helps.

  • Suggested answer
    shivaram Profile Picture
    shivaram 3,315 on at
    RE: I am getting script error like -------- "GetAddress is not defined at eval (eval at RunHandlerInternal (https://info8.crm8.dynamics.com/form/ClientApiWrapper.aspx?ver=-1047458540:153:1), <anonymous>:1:1)"

    Fine. Now you can debug your JS. just debug and check where you are getting error. Do you have retrieve function in JS? I think there you missed. Just debug it once.

  • Sreeekanth Profile Picture
    Sreeekanth 95 on at
    RE: I am getting script error like -------- "GetAddress is not defined at eval (eval at RunHandlerInternal (https://info8.crm8.dynamics.com/form/ClientApiWrapper.aspx?ver=-1047458540:153:1), <anonymous>:1:1)"

    i have done with the following code

    function GetAddress(){

    var accountId = Xrm.Page.getAttribute("parentcustomerid").getValue()[0].id;

    var serverUrl = Xrm.Page.context.getServerUrl();

    var retrievestring = serverUrl + "/xrmservices/2011/OrganizationData.svc/AccountSet?$filter=AccountId eq(guid'" + accountId + "')";

    var recordinfo = Retrieve(retrievestring);

    if (recordinfo != null) {

    var accountAddressAttributes = [recordinfo.results[0].Address1_Name, recordinfo.results[0].Address1_Line1, recordinfo.results[0].Address1_Line2,

    recordinfo.results[0].Address1_Line3, recordinfo.results[0].Address1_City, recordinfo.results[0].Address1_StateOrProvince, recordinfo.results[0].Address1_Country,

    recordinfo.results[0].Address1_Telephone1, recordinfo.results[0].Address1_PostalCode, recordinfo.results[0].new_District, recordinfo.results[0].new_Landmark];

    Xrm.Page.getAttribute("address1_line1").setValue(recordinfo.results[0].Address1_Line1);

    Xrm.Page.getAttribute("address1_line2").setValue(recordinfo.results[0].Address1_Line2);

    Xrm.Page.getAttribute("address1_line3").setValue(recordinfo.results[0].Address1_Line3);

    Xrm.Page.getAttribute("address1_city").setValue(recordinfo.results[0].Address1_City);

    Xrm.Page.getAttribute("address1_stateorprovince").setValue(recordinfo.results[0].Address1_StateOrProvince);

    Xrm.Page.getAttribute("address1_country").setValue(recordinfo.results[0].Address1_Country);

    Xrm.Page.getAttribute("address1_postalcode").setValue(recordinfo.results[0].Address1_PostalCode);

    Xrm.Page.data.entity.save();

    }

     it's showing error like

    3513.Untitledkjnksnldslkmwelmde.png

  • Suggested answer
    shivaram Profile Picture
    shivaram 3,315 on at
    RE: I am getting script error like -------- "GetAddress is not defined at eval (eval at RunHandlerInternal (https://info8.crm8.dynamics.com/form/ClientApiWrapper.aspx?ver=-1047458540:153:1), <anonymous>:1:1)"

    Hi,

    You have syntax issue.

    Try following

    function GetAddress() {

    if (Xrm.Page.getControl("parentcustomerid") != null) {

    if (Xrm.Page.getAttribute("parentcustomerid").getValue() != null && Xrm.Page.getAttribute("parentcustomerid").getValue()[0].id != null) {

    var customerId = Xrm.Page.getAttribute("parentcustomerid").getValue()[0].id;

    var customerType = Xrm.Page.getAttribute("parentcustomerid").getValue()[0].entityType;

    var serverUrl = Xrm.Page.context.getServerUrl();

    if (customerType == "account") {

    var retrievestring = serverUrl + "/xrmservices/2011/OrganizationData.svc/AccountSet?$filter=AccountId eq(guid'" + parentcustomerid+ "')";

    var recordinfo = Retrieve(retrievestring);

    if (recordinfo != null) {

    var accountAddressAttributes = [recordinfo.results[0].Address1_Name, recordinfo.results[0].Address1_Line1, recordinfo.results[0].Address1_Line2,

    recordinfo.results[0].Address1_Line3, recordinfo.results[0].Address1_City, recordinfo.results[0].Address1_StateOrProvince, recordinfo.results[0].Address1_Country,

    recordinfo.results[0].Address1_Telephone1, recordinfo.results[0].Address1_PostalCode, recordinfo.results[0].new_District, recordinfo.results[0].new_Landmark];

    Xrm.Page.getAttribute("address1_line1").setValue(recordinfo.results[0].Address1_Line1);

    Xrm.Page.getAttribute("address1_line2").setValue(recordinfo.results[0].Address1_Line2);

    Xrm.Page.getAttribute("address1_line3").setValue(recordinfo.results[0].Address1_Line3);

    Xrm.Page.getAttribute("address1_city").setValue(recordinfo.results[0].Address1_City);

    Xrm.Page.getAttribute("address1_stateorprovince").setValue(recordinfo.results[0].Address1_StateOrProvince);

    Xrm.Page.getAttribute("address1_country").setValue(recordinfo.results[0].Address1_Country);

    Xrm.Page.getAttribute("address1_postalcode").setValue(recordinfo.results[0].Address1_PostalCode);

    Xrm.Page.data.entity.save();

    Reply

    }

    }

    }

    }

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I am getting script error like -------- "GetAddress is not defined at eval (eval at RunHandlerInternal (https://info8.crm8.dynamics.com/form/ClientApiWrapper.aspx?ver=-1047458540:153:1), <anonymous>:1:1)"

    hi

    whenever u have a script error (eval at runhandler internal http ...)

    thats mean u have a syntax error with ur code

    check it carefully and watch out for small issues like ( " ,' , ; )

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: I am getting script error like -------- "GetAddress is not defined at eval (eval at RunHandlerInternal (https://info8.crm8.dynamics.com/form/ClientApiWrapper.aspx?ver=-1047458540:153:1), <anonymous>:1:1)"

    Hi Sreekant,

    This error generally occurs if CRM is loading the old script or you have some syntax error in the script.

    In you current script, it is missing 4 end braces "}" and have a text "Reply".

    You can use this online link to validate syntax of your script.

    esprima.org/.../validate.html

    Updated version of your script:

    --------------------

    function GetAddress() {

       if (Xrm.Page.getControl("parentcustomerid") != null) {

           if (Xrm.Page.getAttribute("parentcustomerid").getValue() != null && Xrm.Page.getAttribute("parentcustomerid").getValue()[0].id != null) {

               var customerId = Xrm.Page.getAttribute("parentcustomerid").getValue()[0].id;

               var customerType = Xrm.Page.getAttribute("parentcustomerid").getValue()[0].entityType;

               var serverUrl = Xrm.Page.context.getServerUrl();

               if (customerType == "account") {

                   var retrievestring = serverUrl + "/xrmservices/2011/OrganizationData.svc/AccountSet?$filter=AccountId eq(guid'" + parentcustomerid + "')";

                   var recordinfo = Retrieve(retrievestring);

                   if (recordinfo != null) {

                       var accountAddressAttributes = [recordinfo.results[0].Address1_Name, recordinfo.results[0].Address1_Line1, recordinfo.results[0].Address1_Line2,

                       recordinfo.results[0].Address1_Line3, recordinfo.results[0].Address1_City, recordinfo.results[0].Address1_StateOrProvince, recordinfo.results[0].Address1_Country,

                       recordinfo.results[0].Address1_Telephone1, recordinfo.results[0].Address1_PostalCode, recordinfo.results[0].new_District, recordinfo.results[0].new_Landmark];

                       Xrm.Page.getAttribute("address1_line1").setValue(recordinfo.results[0].Address1_Line1);

                       Xrm.Page.getAttribute("address1_line2").setValue(recordinfo.results[0].Address1_Line2);

                       Xrm.Page.getAttribute("address1_line3").setValue(recordinfo.results[0].Address1_Line3);

                       Xrm.Page.getAttribute("address1_city").setValue(recordinfo.results[0].Address1_City);

                       Xrm.Page.getAttribute("address1_stateorprovince").setValue(recordinfo.results[0].Address1_StateOrProvince);

                       Xrm.Page.getAttribute("address1_country").setValue(recordinfo.results[0].Address1_Country);

                       Xrm.Page.getAttribute("address1_postalcode").setValue(recordinfo.results[0].Address1_PostalCode);

                       Xrm.Page.data.entity.save();

                       //Reply

                   }

               }

           }

       }

    }

    ---------------------

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans