function GetCurrentUserRole()
{
var userid = Xrm.Page.context.getUserId();
//Get user Manager
GetManager(userid);
}
// get manager id
function GetManager(userid) {
//alert(userid);
var serverUrl = Xrm.Page.context.getClientUrl();
var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/SystemUserSet?$select=ParentSystemUserId &$filter=SystemUserId eq guid'" + userid + "'";
var retrieveReq = new XMLHttpRequest();
retrieveReq.open("GET", oDataSelect, false);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8");
retrieveReq.onreadystatechange = function () {
GetManagerId(this);
};
retrieveReq.send();
}
function GetManagerId(retrieveReq) {
if (retrieveReq.readyState == 4) {
if (retrieveReq.status == 200) {
var retrieved = JSON.parse(retrieveReq.responseText).d;
var managerGuid = retrieved.results[0].ParentSystemUserId.Id;
var managername = retrieved.results[0].ParentSystemUserId.Name;
var entityType = 'systemuser';
if(managerGuid!=null)
{
Xrm.Page.getAttribute("new_manager").setValue([{ id: managerGuid, name: managername , entityType: entityType}]);
Xrm.Page.getControl("new_manager").setDisabled(true);
}
else
{
Xrm.Page.getControl("new_manager").setDisabled(false);
}
}
}
}
{
var userid = Xrm.Page.context.getUserId();
//Get user Manager
GetManager(userid);
}
// get manager id
function GetManager(userid) {
//alert(userid);
var serverUrl = Xrm.Page.context.getClientUrl();
var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/SystemUserSet?$select=ParentSystemUserId &$filter=SystemUserId eq guid'" + userid + "'";
var retrieveReq = new XMLHttpRequest();
retrieveReq.open("GET", oDataSelect, false);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8");
retrieveReq.onreadystatechange = function () {
GetManagerId(this);
};
retrieveReq.send();
}
function GetManagerId(retrieveReq) {
if (retrieveReq.readyState == 4) {
if (retrieveReq.status == 200) {
var retrieved = JSON.parse(retrieveReq.responseText).d;
var managerGuid = retrieved.results[0].ParentSystemUserId.Id;
var managername = retrieved.results[0].ParentSystemUserId.Name;
var entityType = 'systemuser';
if(managerGuid!=null)
{
Xrm.Page.getAttribute("new_manager").setValue([{ id: managerGuid, name: managername , entityType: entityType}]);
Xrm.Page.getControl("new_manager").setDisabled(true);
}
else
{
Xrm.Page.getControl("new_manager").setDisabled(false);
}
}
}
}
Comments