How to get all the roles for any user?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2021 12:23 AM
I have to get all the roles for a user in an array. if the array is empty then I can declare the answer variable in ACL as false. can somebody give the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2021 09:01 PM
Hi
does my answer resolved your query?
If my answer solve your query please mark as correct so that the thread will appear as resolved for other users who may have a similar query in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 04:45 AM
Not getting the output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2021 09:23 AM
Why are you trying to replace OOB optimized role based ACLs with a performance hog script that does basically the same?
Just list the roles that should grant the access defined in the ACL in the Requires role embedded list of the ACL's definition.
Also your requirement is a little strange, given that lately no user has no roles at all. All users should have at least the snc_internal (or snc_external) role. So the condition that the array of user roles has no items will never be achieved - rendering your check pointless.
Unless your are not providing key information about the requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 11:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 02:53 AM
Hi @Community Alums,
Would you consider this code for your requirement? It will return all roles of the logged-in user.
var role = [];
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user', gs.getUserID());
gr.query();
while (gr.next()) {
role.push(gr.getDisplayValue('role'));
}
gs.log(role, 'Role Info');