Trying to create a breakdown, filter the manager to show all direct and indirect reports
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2024 10:09 AM
In Performance analytic I am trying to create a filter that managers can use to show all submitted incidents from their areas using the report structure so Manager A should be able to see Sub_Manager A1, Sub_Manager A2 and all direct reports to those manager ... continuing to the end of the chain. Right now its incidents but I will need to do the same for other task related items.
I did search and found script that should help but I am struggling to find where this goes.
(function() {
// Create a new Breakdown
var breakdown = new PAUtils().createBreakdown('incident', 'caller_id', 'Caller Breakdown');
// Get the manager of the caller
var caller = new GlideRecord('sys_user');
caller.addQuery('sys_id', gs.getUserID());
caller.query();
if (caller.next()) {
var manager = caller.manager;
}
// Get all direct reports and their reports recursively
function getReports(managerId) {
var reports = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', managerId);
gr.query();
while (gr.next()) {
reports.push(gr.sys_id.toString());
reports = reports.concat(getReports(gr.sys_id.toString()));
}
return reports;
}
var allReports = getReports(manager);
// Filter the Breakdown on the manager and their reports
breakdown.addFilter('caller_id', 'IN', allReports.join(','));
// Save the Breakdown
breakdown.update();
})();
I tried placing this in the breakdown as a script.
But when the daily data collection job runs.
I get a state of collected w/errors
And the error message is
Error during JavaScript evaluation com.snc.pa.dc.ScriptException: "manager" is not defined.ReferenceError: "manager" is not defined. (<refname>; line 18) in script: // Function to get all direct reports and their reports recursively
I have it looking at the caller field and also have tried with the caller.manager field as well.
Not sure what I should do. I looks like manager is not being defined.