- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 05:37 AM
Im trying to create a cusom dynamic filter to show only the incidents that Assignment group is one of user's groups (without parent group).
For some reason it only shows me one group among the groups that i belong to.
I can only see the incidents of one of my groups instead of the two of them:
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 08:00 AM
Hi @Alon Grod,
Then it probably is OOTB in some plugin installed in my instance.
This is the underlying code, which you can use:
/**
Default filter "One of My Groups - d6435e965f510100a9ad2572f2b47744" includes parent groups too
As per defect "DEF0173629" we want only groups the user is part of not parent groups
*/
getGroupsIAmMemberOfExcludeParents: function(userId) {
var groups = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userId);
gr.addQuery('group.active', true);
gr.query();
while (gr.next()) {
var groupId = gr.getValue('group');
if (!gs.nil((groupId)))
groups.push(groupId);
}
return groups;
},
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 08:22 AM
Hi @Alon Grod,
No need to use javascript: int the script field here just use (assuming you are not changing the script include name you already have, and will use this script I sent you)
new getGroups().getGroupsIAmMemberOfExcludeParents(gs.getUserID());
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 06:39 AM
According to documentation, there should already be a "One of My Groups" dynamic filter available. I looked at that and see the script doesn't call a script include at all. It just uses gs.getUser().getMyGroups() in the script field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 06:48 AM
Hi @Alon Grod,
I have the following dynamic filter and script include working in my instance.
The script from above is:
function getMyGroups() {
// Get list of groups the logged in user is a member of
var uID = gs.userID();
gs.info("getMyGroups: User = " + uID);
// get the user groups
var userGroups = [];
var sgm = new GlideRecord("sys_user_grmember");
sgm.addQuery('user', uID);
sgm.query();
while (sgm.next()) {
userGroups.push(sgm.group.getDisplayValue());
}
gs.info("getMyGroups: userGroups = " + userGroups + ".");
// Now query group table for the groups
var grpr = new GlideRecord('sys_user_group');
// Build query to include the groups
var tQuery = '';
for (i=0; i<userGroups.length; i++) {
tQuery += "name" + userGroups[i] + "^";
}
grpr.addEncodedQuery(tQuery);
grpr.query();
gs.info("getMyGroups: processing " + grpr.getRowCount() + " user groups.");
// Get list of groups to use in filter
var queryGrps = '';
while (grpr.next()) {
queryGrps += grpr.sys_id.toString() + ",";
}
gs.info("getMyGroups: queryGrps = " + queryGrps + "." );
return queryGrps;
}
What is returned is a comma separated string with the sys_id values of the group records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 07:50 AM
@Bert_c1 its returning the Parent's assignemt group as well which its not good

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 07:52 AM
@Alon Grod
There should be an existing OOTB dynamic filter which does exactly that:
'Groups I am member of' : /nav_to.do?uri=sys_filter_option_dynamic.do?sys_id=4fef30720f032010717cc562ff767e90
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.