function loggedUser(field) {
var user = Xrm.Page.context.getUserId();
var userId = user.substring(1, 37);
var serverUrl = document.location.protocol;
serverUrl += "//" + document.location.host;
serverUrl += "/" + Xrm.Page.context.getOrgUniqueName();
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
var ODATA_EntityCollection = "/SystemUserSet";
var ODATA_Query = "(guid\'" + userId + "')";
var ODATA_Final_url = serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection + ODATA_Query;
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: ODATA_Final_url,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
var userName = data.d.FullName;
Xrm.Page.getAttribute(field).setSubmitMode("always");
Xrm.Page.getAttribute(field).setValue(userName);
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
alert('Error: ' + ODATA_Final_url);
}
});
}
var user = Xrm.Page.context.getUserId();
var userId = user.substring(1, 37);
var serverUrl = document.location.protocol;
serverUrl += "//" + document.location.host;
serverUrl += "/" + Xrm.Page.context.getOrgUniqueName();
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
var ODATA_EntityCollection = "/SystemUserSet";
var ODATA_Query = "(guid\'" + userId + "')";
var ODATA_Final_url = serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection + ODATA_Query;
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: ODATA_Final_url,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
var userName = data.d.FullName;
Xrm.Page.getAttribute(field).setSubmitMode("always");
Xrm.Page.getAttribute(field).setValue(userName);
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
alert('Error: ' + ODATA_Final_url);
}
});
}
No comments:
Post a Comment