Dynamic Filter Not Working for Array of sys_ids
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 10:25 AM
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:
I have also tried with the script syntax changed to use the new object and class name, but still the same result:
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:
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 02:11 PM - edited 04-12-2023 02:12 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 01:49 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2024 02:53 PM
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