Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Dashboard issue with interactive filter modification

bbf35621
Kilo Sage

Hey guys,

 

I had a customer who wanted to edit the existing dashboard. She wants to modify a dropdown menu to display a list of users who are Client Service Managers. In the Dashboard interactive filter setting, the reference table is the user table but I want to change it to the group member table because that will make it easier to filter so that it only displays a list of users who are in the client service manager group. However, after saving the configuration, I got an error that is preventing me from saving it,

bbf35621_0-1746555818123.png

Does anyone know why I get that error and how can I fix it?

1 ACCEPTED SOLUTION

@bbf35621 

Changing it to "sys_user_grmember" would not work since if the related dependent filters are pointing to "sys_user" ref.

 

To solve this, I would do this below. Create a script include to return the sys ids of users that belong to that group and use a script in the condition builder.

 

javascript: new getGroupMembersUtil().getGrpMem();

javascript: new getGroupMembersUtil().getGrpMem('GroupName'); //You can also do this

 

Let me know if you have any questions:

 

 

folusho_0-1746637143734.png

Script Include: getGroupMembersUtil

var getGroupMembersUtil = Class.create();
getGroupMembersUtil.prototype = {
    initialize: function () {},

    getGrpMem: function () {
        var groupName = 'Network'; // Change to your target group
        var userIds = [];

        var group = new GlideRecord('sys_user_group');
        group.addQuery('name', groupName);
        group.query();
        if (group.next()) {
            var gr = new GlideRecord('sys_user_grmember');
            gr.addQuery('group', group.sys_id);
            gr.query();
            while (gr.next()) {
                userIds.push(gr.user.toString());
            }
        }
        return userIds;
    },

    type: 'getGroupMembersUtil'
};

 

Please mark as helpful if this resolves your issue.

View solution in original post

15 REPLIES 15

@bbf35621 

Changing it to "sys_user_grmember" would not work since if the related dependent filters are pointing to "sys_user" ref.

 

To solve this, I would do this below. Create a script include to return the sys ids of users that belong to that group and use a script in the condition builder.

 

javascript: new getGroupMembersUtil().getGrpMem();

javascript: new getGroupMembersUtil().getGrpMem('GroupName'); //You can also do this

 

Let me know if you have any questions:

 

 

folusho_0-1746637143734.png

Script Include: getGroupMembersUtil

var getGroupMembersUtil = Class.create();
getGroupMembersUtil.prototype = {
    initialize: function () {},

    getGrpMem: function () {
        var groupName = 'Network'; // Change to your target group
        var userIds = [];

        var group = new GlideRecord('sys_user_group');
        group.addQuery('name', groupName);
        group.query();
        if (group.next()) {
            var gr = new GlideRecord('sys_user_grmember');
            gr.addQuery('group', group.sys_id);
            gr.query();
            while (gr.next()) {
                userIds.push(gr.user.toString());
            }
        }
        return userIds;
    },

    type: 'getGroupMembersUtil'
};

 

Please mark as helpful if this resolves your issue.

Hi Folusho,

 

I have tried your code and it doesn't populate the users in the dropdown list. I have added a log in script include and it apparently never trigger the script because there is no log info in the system log.

Here is the result,

bbf35621_0-1746655258436.png

 

bbf35621_1-1746655300181.png

In global script include,

bbf35621_2-1746655336416.png

 

@bbf35621 

 

I tried it and its working for me. Please see below.

 

Interactive Filter on Dashboard

folusho_0-1746659135450.png

 

folusho_3-1746659484945.png

 

 

Can you add the two gs.info to get the log?

 

Script Include

var getGroupMembersUtil = Class.create();
getGroupMembersUtil.prototype = {
    initialize: function() {},

    getGrpMem: function() {

        gs.info("Get List of Sys IDs 1: ");
        var groupName = 'Big Data'; // Change to your target group
        var userIds = [];

        var group = new GlideRecord('sys_user_group');
        group.addQuery('name', groupName);
        group.query();
        if (group.next()) {
            var gr = new GlideRecord('sys_user_grmember');
            gr.addQuery('group', group.sys_id);
            gr.query();
            while (gr.next()) {
                userIds.push(gr.user.toString());
            }
        }

        gs.info("Get List of Sys IDs 2: " + userIds);
        return userIds;
    },

    type: 'getGroupMembersUtil'
};

 

folusho_1-1746659323393.png

 

Group

Please ensure your group has users.

folusho_2-1746659420316.png

 

 

 

 

I have checked everything. The problem is that the script include hasn't been called at all. No script log statement appears. I am not sure how your script got called.

@bbf35621 

 

If you can't get anything in the logs, then do these two things:

 

1. Run the script include in background script.

2. Create a new script include and paste the script.