- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2018 09:45 PM
Hello,
I wanted to get the group names of the user. I have tried using the getMyGroups() method, but its giving sys_id of the group not the display value of the group name.
Please help me in this.
Thanks in advanced.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2018 02:07 AM
If you want it in an array you can just alter Sanjivs example a bit. If you run the code below as a fix script you should first get the names of all groups you are apart of followed by a line with just the first group in that array
var grpArray = [];
var grm = new GlideRecord('sys_user_grmember');
grm.addQuery('user',gs.getUserID());
grm.query();
while (grm.next())
{
grpArray.push(grm.group.getDisplayValue());
}
gs.print(grpArray);
gs.print(grpArray[0]);
Now if you want to use this like you do with getMyGroups() then you have to create a script include which you can call upon just like you do with getMyGroups.
https://docs.servicenow.com/bundle/kingston-application-development/page/script/server-scripting/concept/c_ScriptIncludes.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 08:52 AM
var sys_ids = gs.getUser().getMyGroups().toArray();
names = getNames(sys_ids);
gs.info(names.join(', '));
function getNames(sys_ids ){
var names = [];
for (i=0;i<sys_ids .length;i++){
var gr = new GlideRecord('sys_user_group');
gr.get(sys_ids[i]);
names.push(gr.name.toString());
}
return names;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 11:29 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 11:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 11:49 PM
Hi @DS20 ,
You can try with this script, it will work