Validate if the current user has specific role

Avatar
Jun 11, 2021  1 min read

Validate if the current user has specific role

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 below link:

https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-utility/getglobalcontext/usersettings#roles

Comments
Be the first to comment.
Loading...