Hi Folks,
I was not able get response from Web API. Below is my code...Can suggest me if anything is missing in the below piece of code..I searched for any errors, but couldn't find thing.
var currentUserId = Xrm.Utility.getGlobalContext().userSettings.userId.substr(1, 36);
var userRoleResults = null;
var Buname = null;
var invokeUrl = Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.1/systemusers(" + currentUserId + ")?$select=_businessunitid_value&$expand=businessunitid($select=name)";//,systemuserid&$expand=systemuserroles_association($select=name)
var req = new XMLHttpRequest();
req.open("GET", invokeUrl, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0 ");
req.setRequestHeader("OData-Version", "4.0 ");
if (req.responseXML != null)
req.send();
req.onreadystatechange = function () {
if (this.readyState == 4) {
req.onreadystatechange = null;
if (this.status == 200) {
retrieved = JSON.parse(this.response);
Buname = retrieved.businessunitid.name;
//Buname = retrieved.results[0].BusinessUnitId.Name;
}
else {
var error = JSON.parse(this.response).error;
throw error;
}
//req.send();
}
};
alert(Buname);
The alert seems to be always be Null.
Thank you.