- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2020 07:20 AM
Hello,
I have a reference field to the 'sys_user' table with the name 'name_of_recruiter'. I want the reference field to only show users who are in the recruiting group. However, it is returning every user. Is my script incorrect?
Script include:
var GetGroupMember= Class.create();
GetGroupMember.prototype = {
getMember : function() {
var x = 'e4d875a8db9a5300e21cfd131d961992'; //This is the sys_id of the recruiter group
var user_array = [];
var getMembers = new GlideRecord('sys_user_grmember');
getMembers.addQuery('group',x);
getMembers.query();
while(getMembers.next()) {
user_array.push(getMembers.user + '');
}
return user_array.toString();
}};
Reference qualified in the 'sys_user' reference field 'name_of_recruiter'
javascript:new GetGroupMember().getMember();
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2020 07:56 AM
Ahhh it's Scoped!
Try with:
var GetGroupMember= Class.create();
GetGroupMember.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getMember : function() {
var x = 'e4d875a8db9a5300e21cfd131d961992'; //This is the sys_id of the recruiter group
var user_array = [];
var getMembers = new GlideRecord('sys_user_grmember');
getMembers.addQuery('group',x);
getMembers.query();
while(getMembers.next()) {
user_array.push(getMembers.user + '');
}
gs.info('sys_idIN' + user_array.toString());
return 'sys_idIN' + user_array.toString();
},
type: 'GetGroupMember'
});
Note there's also a gs.info for debugging purposes. So you could check the logs which query is returned and if it's what you would expect.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2020 08:43 AM
SOLVED: there was a single space in front of the reference qualifier, thank you for all your help mark, your code works!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 03:44 AM
Thanks @Mark Roethof this worked for me as well - thanks for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 03:45 AM
Thank you for sharing your screenshots and for the question - I had a similar question and this thread worked for me as well. Appreciate

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2020 07:37 AM
Just reproduced also with your code and the slight adjustment (+ obviously used a different sys_id). Works fine here.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field