Validate if the current user has specific role
1 min read
Charles Llamas
In case you need to validate if the current user has specific security role.
Here is a short code snippet that can be used for validating if the current user has security role by role name.
function userHasRole(roleName) { let currentUserRoles = Xrm.Utility.getGlobalContext().userSettings.roles.getAll(); return currentUserRoles.find(rol => rol.name === roleName) ? true : false; }
If you want to know more about the getGlobalContext.userSettings object open the link below:
https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-utility/getglobalcontext/usersettings#roles