How to get Current Logged in user roles and groups through background script?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2024 11:35 PM
Hi All,
Please help on this
How to get Current Logged in user roles and groups through background script?
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2024 01:40 AM - edited ‎03-22-2024 01:42 AM
Hi @thomas94 ,
Try this Script
//get current user sys id and roles
current_user=gs.getUserID();
current_user_role=gs.getUser().getRoles();
//then fetch the users to the group member table
var groupList=[];
var grmember=new GlideRecord('sys_user_grmember');
grmember.addQuery('user',current_user);
grmember.query();
while(grmember.next())
{
groupList.push(grmember.getDisplayValue('group'))//push the group name into grList List
}
//print the roles and groups of current logged in user
gs.info('Current user has roles - '+current_user_role);
gs.info('Current user has groups - '+groupList)
Regards,
Seraj