Hi,
As all of you aware that the current api being depreciated and the new Web API for DynamicsCRM is on the way. We have a wrote one javascript to fetch currently logged in user id. ie. The user name(email) which is used for login. We successfully consumed the old API and able to get the logged in user user name. Can some one help on doing the same in the Web API. Below is the sample code i have used.
var url = serverUrl + "/api/data/v8.2";
var userRequest = new XMLHttpRequest();
userRequest.open("GET", url + "/systemusers?$filter=ownerid(" + Xrm.Page.context.getUserId().replace("{","").replace("}","") + ")", false);
alert(url + "/systemusers?$filter=ownerid(" + Xrm.Page.context.getUserId().replace("{","").replace("}","") + ")");
userRequest.setRequestHeader("Accept", "application/json");
userRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
userRequest.setRequestHeader("OData-MaxVersion", "4.0");
userRequest.setRequestHeader("OData-Version", "4.0");
userRequest.onreadystatechange = function () {
if (this.readyState == 4) {
userRequest.onreadystatechange = null;
alert(this.status);
if (this.status == 200) {
var data = JSON.parse(this.response).d;
if (data && data.value) {
var userName = retrievedUser.InternalEMailAddress;
return userName;
}
}
else {
return "error";
}
}
};
userRequest.send(null);
*This post is locked for comments
I have the same question (0)