How to get Current Logged in user roles and groups through background script?

thomas94
Tera Contributor

Hi All,

Please help on this

How to get Current Logged in user roles and groups through background script?

5 REPLIES 5

Seraj
Tera Guru
 
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