function CheckUserRole(executionContext)
{
//debugger
var currentUserRoles = Xrm.Utility.getGlobalContext().userSettings.securityRoles;
for (var i = 0; i < currentUserRoles.length; i++)
{
var userRoleId = currentUserRoles[i];
var IsAdmin = IsAdministator(userRoleId);
if (IsAdmin == true)
{
break;
}
}
return IsAdmin;
}
function IsAdministator(roleId)
{
//get the globalContext
var globalContext = Xrm.Utility.getGlobalContext();
//get the rolesArray
var userRoles = globalContext.userSettings.roles;
//initialize return value
var hasRole = false;
//foeach item in array
userRoles.forEach(function hasRoleName(item, index)
{
//Check passed in value for role[].name match
if (item.name === "System Administrator")
{
//match found set return value to true
hasRole = true;
};
});
return hasRole;
}
No comments:
Post a Comment