This code isn't updating the field on the page. I've confirmed the correct values are present in the result object. Anyone able to help?
function onStateLookupFieldChanged() {
var stateId = Xrm.Page.getAttribute('tdn_usstateid').getValue()[0].id;
stateId = stateId.replace('{', '').replace('}', '');
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/tdn_usstates(" + stateId + ")?$select=tdn_statename", 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=\"*\"");
var result = null;
req.onreadystatechange = function (result) {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
result = JSON.parse(this.response);
Xrm.Page.getAttribute("address1_stateorprovince").setValue(result["tdn_statename"]);
} else {
alert(this.statusText);
}
}
};
req.send();
}
*This post is locked for comments