Hello,
I am currently trying the following:
If an account is selected in a look-up field of the opportunity, another field should be filled with the content of a field on the respective account form.
The system used is version "1612 (8.2.15.2) (DB 8.2.15.2) local", so WebAPI cannot be used for this.
So far I have the following code:
function OnLoad(context) {
let formContext = context.getFormContext();
let parentaccount = formContext.getAttribute("parentaccountid").getValue();
if (parentaccount == null) {
return;
}
const type = parentaccount[0].entityType;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts" + "(" + parentaccount[0].id + ")" + "?$select=eno_vertreter1", 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 () {
alert("state: " + this.readyState + " status: " + this.status);
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var representative = result["eno_accountvertreterid"];
alert("the representative: " + respresentative);
formContext.getAttribute("eno_accountvertreterid").value = representative;
} else {
alert("else");
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
When running it, I get the following alerts:
"state: 2 status: 400"
"state: 3 status: 400"
"state: 4 status: 400"
"Bad Request"
Nothing else happens after that.
I have checked the names of the fields several times, there is certainly no error. I have used a similar logic on another system without any problems.
I am very grateful for any advice.