- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 09:57 PM
Hello everyone,
I'm new to servicenow and I need help getting/showing all the groups that the Requested For (user) belongs to.
Could someone kindly assist me with a Script Include and advanced reference qualifier?
I would really appreciate it, thank you in advance
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 05:52 AM - edited 12-03-2024 05:56 AM
@maineeeeeeeee Here is the script include for you.
var GetUserGroups = Class.create();
GetUserGroups.prototype = {
initialize: function () {},
getGroups: function (userId) {
var groups = [];
if (!userId) {
return groups; // Return empty array if no user ID is provided
}
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userId);
gr.query();
while (gr.next()) {
groups.push(gr.group.toString());
}
return "sys_idIN"+groups.toString();
},
type: 'GetUserGroups'
};
Here is how you should specify this reference qualifier.
javascript:new GetUserGroups().getGroups(current.variables.requested_for);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 07:16 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 05:52 AM - edited 12-03-2024 05:56 AM
@maineeeeeeeee Here is the script include for you.
var GetUserGroups = Class.create();
GetUserGroups.prototype = {
initialize: function () {},
getGroups: function (userId) {
var groups = [];
if (!userId) {
return groups; // Return empty array if no user ID is provided
}
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userId);
gr.query();
while (gr.next()) {
groups.push(gr.group.toString());
}
return "sys_idIN"+groups.toString();
},
type: 'GetUserGroups'
};
Here is how you should specify this reference qualifier.
javascript:new GetUserGroups().getGroups(current.variables.requested_for);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 06:22 AM
Hello @Sandeep Rajput ,
I tried doing this, but it still displays all the groups instead of only the ones the user belongs to.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 06:30 AM
Hello @Sandeep Rajput,
I tried doing your code, but it still displays all the groups instead of only the ones the user belongs to.
here's a screenshot. Thank you once again

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 07:16 AM