- 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:56 AM
seems like script is not client callable!
Can you please check once in script include..and make it client callable
Thanks and Regards,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 10:59 AM
- 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 12:20 PM
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.