custom dynamic filter to show only user's groups

Alon Grod
Tera Expert

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.

Screenshot 2023-08-31 at 15.34.49.png

Screenshot 2023-08-31 at 15.35.20.png

Screenshot 2023-08-31 at 15.36.11.png

Screenshot 2023-08-31 at 15.36.27.png

 

I can only see the incidents of one of my groups instead of the two of them:

Screenshot 2023-08-31 at 15.36.55.png

2 ACCEPTED SOLUTIONS

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.

View solution in original post

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.

View solution in original post

14 REPLIES 14

@Peter Bodelier hi, i dont have this dynamic OOTB filter. I only have 'One of my groups' which also return the 'Parent' group of the current group and its not helpful. I only need to user's groups without the parent

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.

@Peter Bodelier hi but what is the difference between what you sent to what i did?

There is very little difference indeed. But what I sent you is created by ServiceNow, and I verified that it is working as per your requirement as well.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

 

 

@Peter Bodelier  so what should be different here according to your adjustment?

 

Screenshot 2023-08-31 at 18.16.56.png