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 12:22 PM
It shouldn't matter too much, but have you tried:
- checking there is an initializer function in your class
- removing the object extension (you don't technically need this unless you're going to use GlideAjax to reference these calls in future, in which case they won't work unless you use getParam anyway)
Your class should look like this:
var AssignmentGroupUtils = Class.create();
// added/changed lines below
AssignmentGroupUtils.prototype = {
initialize: function() {},
// end added lines
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'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 12:54 PM
Hi @wmcgrath ,
Thanks for chiming in to help! I made the modifications you mentioned, but still getting the same result. When I run this fix script:
I am getting the list of sys_id's I would expect:
So it seems to me that something isn't being called correctly from the dynamic filter record, or something in the script itself doesn't play well when being called from a dynamic filter.
I had also found these similar issues reported, but not a really solid explanation of how to make this work: https://www.servicenow.com/community/now-platform-forum/dynamic-filter-not-working-won-t-log-or-retu...
I have tried a bunch of variations of returning .toString() conversions, etc., but nothing seems to actually get the filter to populate from the list view
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 01:33 PM
Hm, weird. It works for me:
Have you checked your acls for that client script? You need to make sure there is an 'execute' permission for that client script: Solved: How to implement an ACL in order to secure client ... - ServiceNow Community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 02:06 PM
Well that is both encouraging and discouraging 😳. Thanks for the link on the ACL's. I did not define an ACL for execute_client_script for the AssignmentGroupUtils script include. I didn't actually know that was a thing! I did check, and there is no specific ACL defined for AssignmentGroupUtils at all (read/write/execute_client_script) that might have auto-generated or anything like that. However, there is a global ACL that looks like it gives access to run client-callable script includes:
I unfortunately don't have security_admin on this instance, so I will have to work with the client to get that if needed, but I think, since there is no script-include level ACL, then the global one would grant access. I assume you just did a copy/paste of the script include code (with your modified lines)?