Dynamic Filter Script not working on Incident 'Opened By' field in Incident Report

WazzaJC
Tera Expert

Dynamic Filter Script not working on Incident 'Opened By' field in Incident Report

Hi guys - I'd really appreciate any help/guidance on why this Script/Dynamic filter is not working for me.

 

I have a Script Include 'ManagerChildGroupUsers' and also a related Dynamic Filter 'ManagerChildGroupUsers'.

*Please see screenshots attached and here below is the Script within the Script Include.

 

When I try to use this on an Incident Report, to show all Incidents 'Opened By' users that are part of the Groups that are child Groups linked to the Parent Group (that I am a Manager of), it just shows 'Empty' for Opened By - it does not load a list of those Users in the 'Opened By' field?

 

Why is this Script Include and Dynamic Filter not working, to show me the 'Opened By' Users, on a standard Incident Report?

 

Many thanks guys 🙂

 

Script Include as follows and screenshots attached

 

function ManagerChildGroupsUsers() {
    var selected = [];
    var grpManager = gs.getUserID();
    //		gs.info('getMyManagedChildGroups: Manager = ' +grpManager);   

    //Get the groups where grpManager is the 'manager'
    var grps = new GlideRecord('sys_user_group');
    grps.addQuery('manager', grpManager);
    grps.query();
    while (grps.next()) {
        //Add the group sys_id values to the returned array
        selected.push(grps.getValue('sys_id'));
    }

    // next get the list of child groups
    var childGroups = [];
    for (i = 0; i < selected.length; i++) {
        var childGrps = new GlideRecord('sys_user_group');
        childGrps.addQuery('parent', selected[i]);
        childGrps.query();
        //			gs.info("Found " + childGrps.getRowCount() + " record where parent = " + selected[i]);
        while (childGrps.next()) {
            childGroups.push(childGrps.getValue('sys_id'));
        }
    }

    // now get the users in the child groups
    var users = [];
    for (i = 0; i < childGroups.length; i++) {
        var userGrps = new GlideRecord('sys_user_grmember');
        userGrps.addQuery('group', childGroups[i]);
        userGrps.query();
        //			gs.info("Found " + userGrps.getRowCount() + " record where group = " + childGroups[i]);
        while (userGrps.next()) {
            //				gs.info("Adding user = " + userGrps.user);
            users.push(userGrps.getValue('user'));
        }
    }

    return users;
}

 

 

 

1 ACCEPTED SOLUTION

Hi @WazzaJC ,
Please change your configurations accrdingly, Its working for me

RahulTalreja_0-1690915497401.png

Create a new script include, name it getMembers, make it client callable and paste the code below.

 

var getMembers = Class.create();
getMembers.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	ManagerChildGroupsUsers:function() {
    var selected = [];
	var i;
    var grpManager = gs.getUserID();
    //		gs.info('getMyManagedChildGroups: Manager = ' +grpManager);   

    //Get the groups where grpManager is the 'manager'
    var grps = new GlideRecord('sys_user_group');
    grps.addQuery('manager', grpManager);
    grps.query();
    while (grps.next()) {
        //Add the group sys_id values to the returned array
        selected.push(grps.getValue('sys_id'));
    }

    // next get the list of child groups
    var childGroups = [];
    for (i = 0; i < selected.length; i++) {
        var childGrps = new GlideRecord('sys_user_group');
        childGrps.addQuery('parent', selected[i]);
        childGrps.query();
        //			gs.info("Found " + childGrps.getRowCount() + " record where parent = " + selected[i]);
        while (childGrps.next()) {
            childGroups.push(childGrps.getValue('sys_id'));
        }
    }

    // now get the users in the child groups
    var users = [];
    for (i = 0; i < childGroups.length; i++) {
        var userGrps = new GlideRecord('sys_user_grmember');
        userGrps.addQuery('group', childGroups[i]);
        userGrps.query();
        //			gs.info("Found " + userGrps.getRowCount() + " record where group = " + childGroups[i]);
        while (userGrps.next()) {
            //				gs.info("Adding user = " + userGrps.user);
            users.push(userGrps.getValue('user'));
        }
    }

    return users;
},
    type: 'getMembers'
});

 

Finally call this dynamic filter from your report:

RahulTalreja_1-1690915631392.png


Hope this works for you!!

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

View solution in original post

8 REPLIES 8

seems like script is not client callable!

Can you please check once in script include..and make it client callable 

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

Hi Rahul - Script is already marked Client Callable (please see attached screenshot).

Thanks.

Hi @WazzaJC ,
Please change your configurations accrdingly, Its working for me

RahulTalreja_0-1690915497401.png

Create a new script include, name it getMembers, make it client callable and paste the code below.

 

var getMembers = Class.create();
getMembers.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	ManagerChildGroupsUsers:function() {
    var selected = [];
	var i;
    var grpManager = gs.getUserID();
    //		gs.info('getMyManagedChildGroups: Manager = ' +grpManager);   

    //Get the groups where grpManager is the 'manager'
    var grps = new GlideRecord('sys_user_group');
    grps.addQuery('manager', grpManager);
    grps.query();
    while (grps.next()) {
        //Add the group sys_id values to the returned array
        selected.push(grps.getValue('sys_id'));
    }

    // next get the list of child groups
    var childGroups = [];
    for (i = 0; i < selected.length; i++) {
        var childGrps = new GlideRecord('sys_user_group');
        childGrps.addQuery('parent', selected[i]);
        childGrps.query();
        //			gs.info("Found " + childGrps.getRowCount() + " record where parent = " + selected[i]);
        while (childGrps.next()) {
            childGroups.push(childGrps.getValue('sys_id'));
        }
    }

    // now get the users in the child groups
    var users = [];
    for (i = 0; i < childGroups.length; i++) {
        var userGrps = new GlideRecord('sys_user_grmember');
        userGrps.addQuery('group', childGroups[i]);
        userGrps.query();
        //			gs.info("Found " + userGrps.getRowCount() + " record where group = " + childGroups[i]);
        while (userGrps.next()) {
            //				gs.info("Adding user = " + userGrps.user);
            users.push(userGrps.getValue('user'));
        }
    }

    return users;
},
    type: 'getMembers'
});

 

Finally call this dynamic filter from your report:

RahulTalreja_1-1690915631392.png


Hope this works for you!!

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

Hello Rahul,

Absolutely brilliant, this is perfect and works great !!

Thanks ever so much for the perfect solution, I really appreciate this kind sir 🙂

Thank you for taking the time to help me Rahul, have a good evening.

Kindest Regards.