- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2024 01:05 AM
Hi all,
I have two fields in the form, Iniator group(Reference to sys_user_group) and Assigned to(reference to sys_user)Field in a Scoped Application. Iniator group is the group that Requestor is a member of. The Requirement is that all the group members of the Iniator Group should not be displayed when search icon is clicked on Assigned to field.
I have tried writing this script, but its not working. Maybe because getUserById() does not work in scoped Application.PFB script
var user = new GlideRecord('sys_user');
user.addQuery('active', true);
user.query();
var arr = [];
while (user.next()) {
if (!gs.getUser().getUserById(user.sys_id).isMemberOf('3bd91ac21b014654bd2d97522a4bcbd3')) {
arr.push(user.sys_id);
}
}
gs.print( arr);
How to achieve this? Please give your Insights.
Thanks in advance!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2024 10:26 AM
So RLQUERYs join to the current table being queried, and allows you to filter the results from the database. It's not a true "join" as the joined table fields aren't available
RLQUERYsys_user_grmember.user,=00,m2m^group=" + current.iniator_group +"ENDRLQUERY
sys_user_grmember.user <- This is the table, and field we want to join on. so we're joining sys_user to this field as the value is a unique sysid
=00 <- This means we only want to return records where no related record is found. We're basically saying "I want all users, where they have no sys_user_grmember record"
m2m <- This is an additional syntax only used when the resulting table is a m2m table
^group=" + current.iniator_group +" <- This is the query. So based on the =00 we're saying "I want all users, where there is no sys_user_grmember record with a group of XYZ".
By inverting your requirement, the logic is passed to the database rather than application layer, improving performance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2024 01:27 AM
Hi @Kieran Anson , whys user is given as 00 and how to give not condition to the whole query?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2024 01:46 AM
Hi @Kieran Anson , why user is given as 00 and i dont want the group memebers of the iniator group not to be displayed on a reference qualifier, so how to give not condition to the whole query?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2024 07:31 AM
Hi @Kieran Anson , its working fine now. could you explain why user is given as 00 and what is m2m and how does this query returns the list of users not in the Iniator group ( By looking at the query, I thought it would return the sys Id's of the users of Initiator group). It helped a lot . Thank you very much !!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2024 10:26 AM
So RLQUERYs join to the current table being queried, and allows you to filter the results from the database. It's not a true "join" as the joined table fields aren't available
RLQUERYsys_user_grmember.user,=00,m2m^group=" + current.iniator_group +"ENDRLQUERY
sys_user_grmember.user <- This is the table, and field we want to join on. so we're joining sys_user to this field as the value is a unique sysid
=00 <- This means we only want to return records where no related record is found. We're basically saying "I want all users, where they have no sys_user_grmember record"
m2m <- This is an additional syntax only used when the resulting table is a m2m table
^group=" + current.iniator_group +" <- This is the query. So based on the =00 we're saying "I want all users, where there is no sys_user_grmember record with a group of XYZ".
By inverting your requirement, the logic is passed to the database rather than application layer, improving performance