Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Reporting using hierarchy

DNier
Tera Contributor

Hi!

I'm trying to create a report in the sc_req_item table, where I need all requests opened by Managers and Directors under a specific user. I have tried the following, but when running the report I don't get any results back, so I'm wondering what I'm doing wrong, of if there is an easier solution that I'm not seeing.

 

I created a callable script include:

 

var GetUsersUnderExecutive = Class.create();
GetUsersUnderExecutive.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getUsers: function() {
        var users = [];
        var gr = new GlideRecord('sys_user');
        gr.addQuery('manager', 'c073f2a51bd85010f6f2ebd22a4bcb0f'); // Use the Sys ID of the executive
        gr.query();
        while (gr.next()) {
            users.push(gr.getValue('sys_id'));
        }
        return users.join(',');
    },
    type: 'GetUsersUnderExecutive'
});
 
DNier_0-1721945733737.png

When running scripts - background this does return a list of sys_ids

 

After this, I go to create the report and in the filter conditions I enter 'sys_id' is one of javascript:new GetUsersUnderExecutive().getUsers();

 

And nothing happens 😞

1 ACCEPTED SOLUTION

jonsan09
Giga Sage
Giga Sage

You should be able to use the condition builder to find any "Opened By" or "Requested For", etc where the manager is a specific Manger/Executive using the condition builder in your report:
2024-07-25 15_36_26-Carvana - Development and 6 more pages - Profile 1 - Microsoft​ Edge.png

 

View solution in original post

2 REPLIES 2

jonsan09
Giga Sage
Giga Sage

You should be able to use the condition builder to find any "Opened By" or "Requested For", etc where the manager is a specific Manger/Executive using the condition builder in your report:
2024-07-25 15_36_26-Carvana - Development and 6 more pages - Profile 1 - Microsoft​ Edge.png

 

DNier
Tera Contributor

Oh wow, completely overlooked that and it's so much easier. Thank you so much!