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.