function GetCurrentUserRole()
{
var roles = Xrm.Page.context.getUserRoles();
for (var i = 0; i < roles.length; i++) {
GetRole(roles[i]);
}
}
function GetRole(roleid) {
var serverUrl = Xrm.Page.context.getClientUrl();
var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/RoleSet?$select=Name&$filter=RoleId eq guid'" + roleid + "'";
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 () {
GetRoleData(this);
};
retrieveReq.send();
}
function GetRoleData(retrieveReq) {
if (retrieveReq.readyState == 4) {
if (retrieveReq.status == 200) {
var retrieved = JSON.parse(retrieveReq.responseText).d;
var roleName = retrieved.results[0].Name;
if(roleName!='Sales Manager' && roleName!='System Administrator' && roleName!='System Customizer')
{
Xrm.Page.getControl("new_status").setDisabled(true);
Xrm.Page.getControl("new_commentsforrejection").setDisabled(true);
}
else
{
Xrm.Page.getControl("new_status").setDisabled(false);
Xrm.Page.getControl("new_commentsforrejection").setDisabled(false);
}
//alert(retrieved.results[0].Name);
}
}
}
{
var roles = Xrm.Page.context.getUserRoles();
for (var i = 0; i < roles.length; i++) {
GetRole(roles[i]);
}
}
function GetRole(roleid) {
var serverUrl = Xrm.Page.context.getClientUrl();
var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/RoleSet?$select=Name&$filter=RoleId eq guid'" + roleid + "'";
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 () {
GetRoleData(this);
};
retrieveReq.send();
}
function GetRoleData(retrieveReq) {
if (retrieveReq.readyState == 4) {
if (retrieveReq.status == 200) {
var retrieved = JSON.parse(retrieveReq.responseText).d;
var roleName = retrieved.results[0].Name;
if(roleName!='Sales Manager' && roleName!='System Administrator' && roleName!='System Customizer')
{
Xrm.Page.getControl("new_status").setDisabled(true);
Xrm.Page.getControl("new_commentsforrejection").setDisabled(true);
}
else
{
Xrm.Page.getControl("new_status").setDisabled(false);
Xrm.Page.getControl("new_commentsforrejection").setDisabled(false);
}
//alert(retrieved.results[0].Name);
}
}
}
Comments