- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2023 11:48 AM
Hello Community members,
I want to create a BR (client callable) for a custom dynamic filter option 'Not one of my Group', which displays only those records of which loggedin user is NOT a member of.
For this I tried below useful article (refer URL-
but not getting the desired results.
Requesting to please help with the BR scripting part to satisfy the above explained filter condition.
Will mark the desired response as helpful & accepted!
Thanks in Advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2023 11:54 PM
Okay, so you want it to be available as a dynamic filter,
Let's make some minor changes, to make it work, see example below.
Script include:
var MembershipUtil = Class.create();
MembershipUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
notMyGroups : function (){
var notMemberOf = [];
var groupGR = new GlideRecord('sys_user_group');
groupGR.query();
while (groupGR.next()){
var memberGR = new GlideRecord('sys_user_grmember');
memberGR.addEncodedQuery('user=' + gs.getUserID() + '^group=' + groupGR.getUniqueValue());
memberGR.query();
if (!memberGR.hasNext()){
notMemberOf.push(groupGR.getUniqueValue());
}
}
return notMemberOf; // returns sysID of all groups which logged in user is not member of
},
type: 'MembershipUtil'
});
Dynamic filter:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 02:04 AM
Thank you for your kind words @rishabh31 !
The changes I did was to reflect it to be available as a dynamic filter.
In my first response I thought you needed a script include that returned all sysID of groups that a specific (function input) user was not member of.
The result was returned as a comma-separated string.
In this updated script, I instead went without parameters, and went with the currently logged in user (gs.getUser...)
And the results are returned as an Array of the sysID of the matching groups.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2023 12:59 PM
If you want a comma-separated list of group names, as the link you have shows, BR script logic follows:
// Get list of groups the logged in user is not a member of
//
var uID = gs.userID();
gs.info("script: User = " + uID);
// get the user groups
var sgm = new GlideRecord("sys_user_grmember");
var userGroups = [];
sgm.addQuery('user', uID);
sgm.query();
while (sgm.next()) {
userGroups.push(sgm.group.getDisplayValue());
}
gs.info("script: userGroups = " + userGroups + ".");
// Now query group table for the remaining groups
var grpr = new GlideRecord('sys_user_group');
// Build query to exclude the groups
var tQuery = '';
for (i=0; i<userGroups.length; i++) {
tQuery += "name!=" + userGroups[i] + "^";
}
grpr.addEncodedQuery(tQuery);
grpr.query();
gs.info("script: processing " + grpr.getRowCount() + " user groups.");
// Get list of groups to user in filter
var queryGrps = '';
while (grpr.next()) {
queryGrps += grpr.name + ",";
gs.info("group " + grpr.name + ".");
}
gs.info("queryGrps = " + queryGrps + "." );
(comment out or remove the gs.info() debug messages).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2023 01:19 PM
OLaN's solution may be better that a BR, for a Dynamic Filter.