- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 09:37 AM
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;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 11:47 AM - edited 08-01-2023 11:50 AM
Hi @WazzaJC ,
Please change your configurations accrdingly, Its working for me
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:
Hope this works for you!!
Thanks and Regards,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 10:00 AM
Hi @WazzaJC , try with
new <script include name>().ManagerChildGroupsUsers()
In the script field
And also check if your script is client callable.
Thanks and Regards,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 10:17 AM
Also I could notice..you haven't declared the "var i=0;"
please add this line in the start of script
Thanks and Regards,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 10:42 AM
Hi Rahul, I have added this but it doesn't seem to make any difference?
Here is the updated Script - is this looking correct ?
Thanks.
function ManagerChildGroupsUsers() {
var i = 0;
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 10:41 AM
Hi Rahul, thanks for your help.
The Script Include name is: ManagerChildGroupUsers()
I am using this - is this not correct as it is ?