Skip to content
Charles Llamas

Validate if the current user has specific role

1 min read

This post is only available in English.

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

Related posts

Comments

No comments yet

No comments yet. Yours would be the first.

Leave a comment

Never published. Only used if I need to reply to you.

← All posts