- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2025 04:41 AM
Hi,
I have a request for a catalog item that requires a field that references the sys_user table to display a managers Direct and also Indirect reports (No other users should appear). I've had no issues getting it to display direct reports with a reference qualifier but I can't figure out how to make it also display any Indirect reports.
I've tried using a script includes along with a client script but i'm not having much luck and all users are being returned.
This is the Script Includes which is Client callable and accessible from all scopes:
This is the Client Script which runs on load for the catalog item in question:
Any advice would be appreciated.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2025 04:47 AM
so you want the direct manager rolling up to the next level and get all those users?
if yes then use this in advanced ref qualifier, no client script required
javascript: 'sys_idIN' + new GetUserReports().getReportUserIDs();
Script Include:
var GetUserReports = Class.create();
GetUserReports.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getReportUserIDs: function() {
var currentUser = gs.getUserID();
var reports = [];
function getReports(managerId) {
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', managerId);
gr.addQuery('active', true);
gr.query();
while (gr.next()) {
var id = gr.getUniqueValue();
if (reports.indexOf(id) === -1) {
reports.push(id);
getReports(id); // Recursive for indirect reports
}
}
}
getReports(currentUser);
// Always include the current user too if needed
// reports.push(currentUser);
// Return as a comma-separated string
return reports.join(',');
},
// This is needed for GlideAjax
type: 'GetUserReports'
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2025 05:11 AM
the script I shared and the reference qualifier I shared should cover that scenario
Did you apply that and test it?
Example Scenario
Suppose:
You (manager) have 5 direct reports: A, B, C, D, E.
A manages 5 people: F, G, H, I, J.
B, C, D, E have no reportees.
Result:
The script will return sys_ids for:
A, B, C, D, E (your direct reports)
F, G, H, I, J (A's direct reports; your indirect reports)
Total: 10 users.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2025 04:47 AM
so you want the direct manager rolling up to the next level and get all those users?
if yes then use this in advanced ref qualifier, no client script required
javascript: 'sys_idIN' + new GetUserReports().getReportUserIDs();
Script Include:
var GetUserReports = Class.create();
GetUserReports.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getReportUserIDs: function() {
var currentUser = gs.getUserID();
var reports = [];
function getReports(managerId) {
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', managerId);
gr.addQuery('active', true);
gr.query();
while (gr.next()) {
var id = gr.getUniqueValue();
if (reports.indexOf(id) === -1) {
reports.push(id);
getReports(id); // Recursive for indirect reports
}
}
}
getReports(currentUser);
// Always include the current user too if needed
// reports.push(currentUser);
// Return as a comma-separated string
return reports.join(',');
},
// This is needed for GlideAjax
type: 'GetUserReports'
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2025 05:06 AM
Hi Ankur,
Thanks for the response.
I'm looking for it to roll down. E.g: I manage 5 people, 1 of these people manages 5 other people. I should see 10 people in the list. Both my direct reports and the people who report into my direct reports.
Thanks,
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2025 05:11 AM
the script I shared and the reference qualifier I shared should cover that scenario
Did you apply that and test it?
Example Scenario
Suppose:
You (manager) have 5 direct reports: A, B, C, D, E.
A manages 5 people: F, G, H, I, J.
B, C, D, E have no reportees.
Result:
The script will return sys_ids for:
A, B, C, D, E (your direct reports)
F, G, H, I, J (A's direct reports; your indirect reports)
Total: 10 users.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2025 06:04 AM
Thanks Ankur, I added this as a reference qualifier which solved the issue:
javascript: new GetUserReports().getReportUserIDs();