Display users NOT belonging to specific group in a catalog variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 10:39 PM
Hello,
For a catalog item, I have a requirement to display members not belonging to a specific group on a catalog variable referencing to sys_user table.
I have written the below global not client callable script include as -

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 11:10 PM - edited 09-20-2024 01:04 AM
Hi @Somujit1, if I understood correct, you want to use this function as reference qualifier. If so, then you need to return a query and not an array of user display values. Something like sys_idIN<sys_id_user_1>,<sys_id_user2>,<...>.
Check this article: https://www.servicenow.com/community/developer-articles/reference-qualifiers-in-servicenow/ta-p/2765...
This should work (not tested):
var GetNonItilUsers = Class.create();
GetNonItilUsers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize: function() {},
getUser: function() {
var userArray = [];
var users = new GlideRecord('sys_user');
users.addActiveQuery();
users.query();
while (users.next()) {
var userGroup = new GlideRecord('sys_user_grmember');
userGroup.addQuery('user', users.sys_id);
userGroup.addQuery('group','a671c95edb875910cb183632f39619bf');
userGroup.query();
if (!userGroup.hasNext()) {
userArray .push(users.getUniqueValue());
}
return "sys_idIN" + userArray .join(",");
}
},
type: 'GetNonItilUsers '
};
});
Additional I would optimize your code:
var GetNonItilUsers = Class.create();
GetNonItilUsers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUser: function() {
var userArray = [];
var userGroup = new GlideRecord('sys_user_grmember');
userGroup.addQuery('group', 'a671c95edb875910cb183632f39619bf'); //recommend to define this sys_id in a sys_properties
userGroup.query();
while (userGroup.next()) {
userArray.push(userGroup.getValue('user'));
}
if (userArray.length > 0) {
return "sys_idNOT IN" + userArray.join(",");
}
return "";
},
type: 'GetNonItilUsers'
});
Greets
Daniel
Please mark reply as Helpful/Correct, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 12:26 AM - edited 09-20-2024 12:27 AM
Hi @Daniel Borkowi1 ,
Thankyou for your reply. I have updated the script include to return a query as suggested by you and as below, however the variable dropdown is still showing all the users belonging to the sys id group 😞

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2024 10:38 PM - edited 09-22-2024 10:41 PM
Hi @Somujit1 , the issue is your selected function getDisplayValue, it doesn't return a sys_id. Use getUniqueValue instead.
I really recommend to use this algorithm:
getUser: function() {
var userArray = [];
var userGroup = new GlideRecord('sys_user_grmember');
userGroup.addQuery('group', 'a671c95edb875910cb183632f39619bf'); //recommend to define this sys_id in a sys_properties
userGroup.query();
while (userGroup.next()) {
userArray.push(userGroup.getValue('user'));
}
if (userArray.length > 0) {
return "sys_idNOT IN" + userArray.join(",");
}
return "";
},
Greets
Daniel
Please mark reply as Helpful/Correct, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 12:35 AM - edited 09-20-2024 12:52 AM
@Somujit1 is your Script Include Client Callable?
This works for me. In my group there are 2 user, the reference shows all other users.Greets
Daniel
Please mark reply as Helpful/Correct, if applicable. Thanks!