Hello Ravi, i refracted my code as per yours above, and add it ad onLoad event, but unfortunately its not working as expected, ill attached my code below.
// API retrive for Speialty in credentialing
function setRevSpecialty(executionContext) {
var formContext = executionContext.getFormContext();
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/hqi_credentialings()?$select=hqi_specialty", 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 hqi_specialty = result["hqi_specialty"];
var hqi_specialty_formatted = result["hqi_specialty@OData.Community.Display.V1.FormattedValue"];
//checking credentialing specialty value and passing it to hqi_reviewerspecialty1
if (hqi_specialty != null) {
formContext.getAttribute("hqi_reviewerspecialty1").setValue(hqi_specialty)
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
};