- 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 07:36 AM
Hi there,
There's a small error in your return.
Change:
return user_array.toString();
Into:
return 'sys_idIN' + user_array.toString();
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 07:52 AM

- 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:03 AM
It is throwing an error:
Invalid query detected, please check logs for details [Unknown field null in table sys_user]