Hello All, I am using this JS on an onchange event of a field and the output is 'Bad Request'. Please see the script below. Thank you!
function displayacctname() {
if (Xrm.Page.data.entity.attributes.get("new_lookuptest").getValue() != null) {
var CustomerId = Xrm.Page.data.entity.attributes.get("new_lookuptest").getValue()[0].id;
var CustomerName = Xrm.Page.data.entity.attributes.get("new_lookuptest").getValue()[0].name;
var CustomerType = Xrm.Page.data.entity.attributes.get("new_lookuptest").getValue()[0].entityType;
var api = Xrm.Page.context.getClientUrl();
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/new_accountfuels?$select=new_fueldba,new_fulladdress&$filter=new_accountfuelid eq '" +CustomerId+"'", 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 new_fueldba = result["new_fueldba"];
var new_fulladdress = result["new_fulladdress"];
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
};
//Display the lookup name
alert(api);
alert(CustomerName);
alert(CustomerId);
alert(api);
};
*This post is locked for comments