I need to autofill this field when the parent field contains data without click and selecting the field related, theres always only a result related, I already research I know a Javascript code must be load on onChange-field and I have to use a Web API but I dont know how to do that, the code I found doesnt work with me, I dont know what I am doing wrong. I am stuck on this.
Any help will be appreciate.
I found this code and I adapted but doesn't work.
_____________________
function setExpenseCategorybasedonVendor() {
var lookup1 = Xrm.Page.getAttribute("new_cdigodesocio").getValue()[0].id;
var clientUrl = Xrm.Page.context.getClientUrl();
var query = clientUrl + "/api/data/v8.0/new_membresacliente(" + lookup1.slice(1, -1) + ")?$select=_new_cuenta_value";
makeRequest('GET', query)
.then(function (res) {
var res2 = JSON.parse(res);
var guid = res2._cse_expense_category_value;
var query2 = clientUrl + "/api/data/v8.0/new_membresacliente(" + guid + ")?$select=cse_name";
makeRequest('GET', query2)
.then(function (response) {
var res3 = JSON.parse(response);
var value = new Array();
value[0] = new Object();
value[0].id = guid;
value[0].name = res3.cse_name;
value[0].entityType = "new_membresacliente";
Xrm.Page.getAttribute("new_cuenta").setValue(value);
})
.catch(function (err) {
console.error('there was an error!', err.statusText);
});
})
.catch(function (err) {
console.error(' there was an error!', err.statusText);
});
}________________________
Error.







