Creating Dynamic Filter

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 12:30 PM
I am creating a dynamic filter so that a user can pull a list of all records created by any member of a group that they are a member of.
ie: If John Smith is a member of the Service Desk group and the On-Call group, then the list would return records created by John Smith and any other users in those two groups.
I created the Script Include below that retrieves the user's groups, and then queries for the members of those groups. From there, the list is supposed to query the Opened By field in the example I'm testing (Requested Items table), but nothing is returning. It's not returning an error either, so I'm not sure what's going on.
var myTeamsRequests = Class.create();
myTeamsRequests.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRecordsCreatedByGroupMembers : function(user) {
var myGroups = gs.getUser().getMyGroups();
var userSet = new Set(); // To ensure uniqueness
while (myGroups.hasNext()) {
var group = myGroups.next();
var groupId = group.getValue('sys_id');
// Query sys_user_grmember table for users in the group
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('group', groupId);
grMember.query();
while (grMember.next()) {
var userId = grMember.getValue('user');
if (!userSet.has(userId)) {
userSet.add(userId);
}
}
}
return userSet;
},
type: 'myTeamsRequests'
});
Here is my Dynamic Filter options setup as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2025 04:47 PM
@Aaron Duncan Could you share the dynamic filter configuration??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 09:34 PM
try this
var myTeamsRequests = Class.create();
myTeamsRequests.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRecordsCreatedByGroupMembers: function() {
var myGroups = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());
var userArray = [];
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('group', 'IN', myGroups.toString());
grMember.query();
while (grMember.next()) {
var userId = grMember.getValue('user');
userArray.add(userId);
}
return userArray.toString();
},
type: 'myTeamsRequests'
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2025 05:03 AM
Sure, here's my Dynamic Filter Options.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2025 05:57 AM - edited 07-14-2025 05:59 AM
@Aaron Duncan As per the product doc, Reference script is optional if you are using javascript in the script field.
So, try removing the reference script and check. Also, in your script include, you shouldn't extend the AbstractAjaxProcessor class.