Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Auto populate quote - ReferenceError: onLoad is not defined at eval (eval at RunHandlerInternal

Posted on by Microsoft Employee

I am trying to assign values to a field based on the selection of _productbylocation and I am getting this error :ReferenceError: onLoad is not defined at eval (eval at RunHandlerInternal .....

function onLoad() {
Xrm.Page.ui.controls.get("billto_composite").setVisible(false);
Xrm.Page.ui.controls.get("shipto_composite").setVisible(false);
}

function onAccountSelection() {
var ExistingAccount = Xrm.Page.getAttribute("customerid");

// Xrm.Page.getAttribute("_billtocountry").setValue(null);
// Xrm.Page.getAttribute("_outsidesalesperson").setValue(null);
// Xrm.Page.getAttribute("_salesrepresentative").setValue(null);

if (ExistingAccount != null) {
var lookupCustID = ExistingAccount.getValue(); //Check for Lookup Value
if (lookupCustID != null) {
//Xrm.Page.getAttribute("accountid").setValue(lookupCustID);
var lookupAccountGuid = lookupCustID[0].id; // To get record GUID
if (lookupAccountGuid != null) {
//alert(lookupAccountGuid);
lookupAccountGuid = lookupAccountGuid.replace(/\{|\}/gi, "");
var req = new XMLHttpRequest();
req.open(
"GET",
Xrm.Page.context.getClientUrl() +
"/api/data/v8.2/accounts(" +
lookupAccountGuid +
")?$select=address1_country,address2_addressid,address2_addresstypecode,address2_city,address2_country,address2_line1,address2_line2,address2_line3,address2_name,address2_postalcode,address2_stateorprovince,paymenttermscode,_country2_value,_outsidesalesperson_value,_salesrepresentative_value",
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 address1_country = result["address1_country"];
var address2_addressid = result["address2_addressid"];
var address2_addresstypecode = result["address2_addresstypecode"];
var address2_addresstypecode_formatted =
result[
"address2_addresstypecode@OData.Community.Display.V1.FormattedValue"
];
var address2_city = result["address2_city"];
var address2_country = result["address2_country"];
var address2_line1 = result["address2_line1"];
var address2_line2 = result["address2_line2"];
var address2_line3 = result["address2_line3"];
var address2_name = result["address2_name"];
var address2_postalcode = result["address2_postalcode"];
var address2_stateorprovince = result["address2_stateorprovince"];
var paymenttermscode = result["paymenttermscode"];
var paymenttermscode_formatted =
result[
"paymenttermscode@OData.Community.Display.V1.FormattedValue"
];
var _country2_value = result["_country2_value"];
var _country2_value_formatted =
result[
"_country2_value@OData.Community.Display.V1.FormattedValue"
];
var _country2_value_lookuplogicalname =
result[
"_country2_value@Microsoft.Dynamics.CRM.lookuplogicalname"
];

//Inside sales persons....
// var _insidesalesperson_value = result["_insidesalesperson_value"];
// var _insidesalesperson_value_formatted = result["_insidesalesperson_value@OData.Community.Display.V1.FormattedValue"];
// var _insidesalesperson_value_lookuplogicalname = result["_insidesalesperson_value@Microsoft.Dynamics.CRM.lookuplogicalname"];

//Outside sales person ..
var _outsidesalesperson_value =
result["_outsidesalesperson_value"];
var _outsidesalesperson_value_formatted =
result[
"_outsidesalesperson_value@OData.Community.Display.V1.FormattedValue"
];
var _outsidesalesperson_value_lookuplogicalname =
result[
"_outsidesalesperson_value@Microsoft.Dynamics.CRM.lookuplogicalname"
];

// Sales rep ...
var _salesrepresentative_value =
result["_salesrepresentative_value"];
var _salesrepresentative_value_formatted =
result[
"_salesrepresentative_value@OData.Community.Display.V1.FormattedValue"
];
var _salesrepresentative_value_lookuplogicalname =
result[
"_salesrepresentative_value@Microsoft.Dynamics.CRM.lookuplogicalname"
];
Xrm.Page.getAttribute("billto_line1").setValue(address2_line1);
Xrm.Page.getAttribute("billto_line2").setValue(address2_line2);
Xrm.Page.getAttribute("billto_line3").setValue(address2_line3);
Xrm.Page.getAttribute("billto_city").setValue(address2_city);
Xrm.Page
.getAttribute("billto_stateorprovince")
.setValue(address2_stateorprovince);
Xrm.Page
.getAttribute("billto_postalcode")
.setValue(address2_postalcode);
//Xrm.Page.getAttribute("_billtocountry").setValue(_country2_value);

Xrm.Page.data.entity.attributes
.get("paymenttermscode")
.setValue(paymenttermscode);
if (_country2_value != null) {
var object = new Array();
object[0] = new Object();
object[0].id = _country2_value;
object[0].name = _country2_value_formatted;
object[0].entityType = _country2_value_lookuplogicalname;
Xrm.Page.getAttribute("_billtocountry").setValue(object);
}
// Outside sales persons
if (_outsidesalesperson_value != null) {
var object = new Array();
object[0] = new Object();
object[0].id = _outsidesalesperson_value;
object[0].name = _outsidesalesperson_value_formatted;
object[0].entityType =_outsidesalesperson_value_lookuplogicalname;
Xrm.Page
.getAttribute("_outsidesalesperson")
.setValue(object);
};
// Sales rep.
if (_salesrepresentative_value != null) {
var object = new Array();
object[0] = new Object();
object[0].id =_salesrepresentative_value;
object[0].name =_salesrepresentative_value_formatted;
object[0].entityType =_salesrepresentative_value_lookuplogicalname;
Xrm.Page
.getAttribute("_salesrepresentative")
.setValue(object);
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
};
};
};
};
}
//alert("done");

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Auto populate quote - ReferenceError: onLoad is not defined at eval (eval at RunHandlerInternal

    Thanks, still the same error just different alert  

  • Verified answer
    Rajkumar Rajaraman Profile Picture
    Rajkumar Rajaraman 18,108 on at
    RE: Auto populate quote - ReferenceError: onLoad is not defined at eval (eval at RunHandlerInternal

    Try this:

    Settings -> Administration -> System Settings -> General -> Use legacy form rendering

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans