- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 12:00 AM
Hi All,
There is one user table reference type variable in a catalog item and we want on that variable on those users records should show who report to the requestor.
For example I am raising a request from the catalog item in that case on that variable drop down list only those user name should show whose manager is me or their managers manager is me and so on....
I know we can achieve this using reference qualifier but I need help to built the logic.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 12:10 AM
@v-paulp Create a dynamic reference qualifier and put the following function inside it. Call this script include function from your reference qualifier.
function getMyReportees() {
var userList = [];
var currentUserId = gs.getUserID(); // Get the logged-in user's ID
// Function to recursively find users reporting to a manager
function getUsersReportingTo(managerId) {
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', managerId);
gr.query();
while (gr.next()) {
if (!userList.includes(gr.sys_id.toString())) {
userList.push(gr.sys_id.toString());
getUsersReportingTo(gr.sys_id); // Recursively find users under this manager
}
}
}
// Add the current user's direct reports
getUsersReportingTo(currentUserId);
// Return query for the user table
return 'sys_idIN' + userList.join(',');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 12:10 AM
@v-paulp Create a dynamic reference qualifier and put the following function inside it. Call this script include function from your reference qualifier.
function getMyReportees() {
var userList = [];
var currentUserId = gs.getUserID(); // Get the logged-in user's ID
// Function to recursively find users reporting to a manager
function getUsersReportingTo(managerId) {
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', managerId);
gr.query();
while (gr.next()) {
if (!userList.includes(gr.sys_id.toString())) {
userList.push(gr.sys_id.toString());
getUsersReportingTo(gr.sys_id); // Recursively find users under this manager
}
}
}
// Add the current user's direct reports
getUsersReportingTo(currentUserId);
// Return query for the user table
return 'sys_idIN' + userList.join(',');
}