- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 01:08 PM
I have an user reference field. I have two requirements
Users belonging to app.support group should only show up in the reference field or if the employment_type is "External)
How can I achieve this ?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 06:46 PM
Sorry. Missed the reply on changing the variable type.
Script Include should be as follows using boolean variable 'u_boolean_1'
var GetUserSys = Class.create();
GetUserSys.prototype = {
initialize: function() {},
GetUserSys: function() {
var userList = [];
var grGrMember = new GlideRecord('sys_user_grmember');
grGrMember.addQuery('group.name', '<name of group>'); // example 'Software'
grGrMember.query();
while (grGrMember.next()) {
userList.push(grGrMember.user.toString());
}
var grUser = new GlideRecord('sys_user');
grUser.addQuery('u_boolean_1', true);
grUser.addActiveQuery();
grUser.query();
while (grUser.next()) {
userList.push(grUser.sys_id.toString());
}
var arrayUtil = new ArrayUtil();
userList = arrayUtil.unique(userList);
return 'sys_idIN' + userList.join(',');
},
type: 'GetUserSys'
};

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 01:44 PM
In the script include, fetch the sys_id of users who are the member of app.support group, You can also fetch the users who are external users, Then you can add them to comma separated list and return from script include
function GetUserSys() {
var gp = ' ';
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', 'sys_id of the group goes here'); //fileter for your group
gr.query();
while (gr.next()) {
if (gp.length > 0) {
gp += (',' + gr.user);
} else {
gp = gr.user;
}
}
var gr1 = new GlideRecord('sys_user');
gr1.addQuery('employment_type', 'external');
gr1.query();
while (gr.next()) {
if (gp.length > 0) {
gp += (',' + gr1.user);
} else {
gp = gr1.user;
}
}
return 'sys_idIN' + gp;
}
reference- https://servicenowguru.com/scripting/script-includes-scripting/advanced-reference-qualifier-script-include/
If there are large number of users this approach would have performance implications.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 02:15 PM
I'm only able to retrieve users from the group, but unable to retrieve users whose employment type is " External"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 02:28 PM
Could you please check, the employment type field is available in sys_user table, I think it is a custom field in your instance. Please give the exact column name and value in the query condition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 02:44 PM