We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Dynamic Filter Not Working for Array of sys_ids

mgroversigital
Tera Expert

Hello, 

 

I'm building out a dynamic filter so that I can report on tickets that are assigned to groups managed by the logged in user, or the assigned to is in my management chain (I either manage them directly, or I manage someone who manages them...keep going down the tree recursively).  

 

This is the script include I wrote for these functions:

Name: AssignmentGroupUtils
Application: Global
Accessible from: All Application Scopes

Client Callable: True

var AssignmentGroupUtils = Class.create();
AssignmentGroupUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	getTeamAssignmentGroups: function(user) {
		var groupIDs = [];
		var userArray = this.getMyManagementChain(user, []);
		var queryStr = "manager=" + userArray[0];
		for (var i = 1; i < userArray.length; i++) {
			queryStr += "^ORmanager=" + userArray[i];
		}
		
		var groupGR = new GlideRecord('sys_user_group');
		groupGR.addEncodedQuery(queryStr);
		groupGR.addActiveQuery();
		groupGR.query();
		
		while (groupGR.next()) {
			groupIDs.push(groupGR.sys_id.toString());
		}
		
		return groupIDs;
		
		
	},
	
	usersReportToMe: function() {
		var user = gs.getUserID();
		var array = [];
		return this.getMyManagementChain(user, array);
	},

    getMyManagementChain: function(manager, list) {
		var arrUtil = new ArrayUtil();
            if (!arrUtil.contains(list, manager)) {
                list.push(manager);
            }
		
        var user = new GlideRecord('sys_user');
        user.addQuery('manager', manager);
        user.addActiveQuery();
        user.query();
        if (!user.hasNext()) {
            return list;
        } else {
            while (user.next()) {
                list = this.getMyManagementChain(user.sys_id.toString(), list);
                var au = new ArrayUtil();
                if (!au.contains(list, user.sys_id.toString())) {
                    list.push(user.sys_id.toString());
                }
            }
            return list;
        }
    },

    type: 'AssignmentGroupUtils'
});

 

 

This is the dynamic filter I created to run this:

mgroversigital_0-1681319911736.png


I have also tried with the script syntax changed to use the new object and class name, but still the same result:

mgroversigital_3-1681320277827.png

 

 

I created a fix script to help debug this, and when just calling the functions to print a list of sys_id's, it's getting results.  And when I paste that list of sys_id's into the list view filter, it's returning the correct users and groups.  However, when using the dynamic filter, the results are coming back empty:

mgroversigital_2-1681320200086.png

 

mgroversigital_1-1681320146447.png

 

 

I think the logic for bringing back the sys_id list is sound, and it's working from direct fix script calls, but the filter is failing.  Any idea where to start looking?  It seems a lot of debugging options are unavailable when looking at the dynamic filters.

 

7 REPLIES 7

Yes, I did - and I tested with a background script:

 

 

 

var agu = new AssignmentGroupUtils();

gs.log(gs.getUserName()); // prints my name
gs.log(agu.usersReportToMe()); // prints my sys_id given I have no reports

 

 

mgroversigital
Tera Expert

Apologies as I have been distracted from working on this much due to other issues.  I was able to procure security_admin, and also exported the code into a PDI.  However, I'm still getting empty results when I actually use the dynamic filter in a list view.  I'm not really sure where to go from here in testing this.

Sandeep Shah
Tera Contributor

i am having the same issue...Did you fix the issue? and if yes - how? I am able to print sysid's in the background script but the same script in the dynamic filter not working...thanks