Report Filtering based on user attribute

saminsaju
Tera Contributor

Hello ServiceNow Community,

 

I have a requirement where I need to create the reports based on the conditions below. I am not familiar with how to enforce this logic, and hoping you can help resolve.

 

1. Filter by Tickets Opened By the user's manager. I have a requested by and requested for fields available.

 

Thank you in advance for your help.

 

Sam

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@saminsaju 

so when user ABC checks the report he/she should see tickers open by his/her manager?

you will have to use scripted filter condition

Script Include: client callable

function getRecords() {
    var arr = [];
    var manager = gs.getUser().getManagerID();
    var gr = new GlideRecord("incident");
    gr.addQuery("opened_by", manager);
    gr.query();
    while (gr.next()) {
        arr.push(gr.getUniqueValue());
    }
    return arr.toString();
}

AnkurBawiskar_0-1739632283748.png

 

Then call in report filter condition as this

SysId [IS ONE OF] javascript: getRecords()

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

My requirement is slightly different.

Basically, we need to pull a report on tickets where the requested by is the manager of the requested for user.

The report will be viewed by the leadership to understand the volume.

@saminsaju 

you can tweak the script I shared like this

function getRecords() {
    var arr = [];
    var gr = new GlideRecord("table");
    gr.addEncodedQuery("requestedForISNOTEMPTY");
    gr.query();
    while (gr.next()) {
        var manager = gr.requestedFor.manager;
        var rec = new GlideRecord("table");
        rec.addQuery('requestedBy', manager);
        rec.query();
        while (rec.next()) {
            arr.push(rec.geUniqueValue());
        }

    }
    return arr.toString();
}

I believe I have provided enough guidance and you can enhance the script further as per your requirement and based on your developer skills.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader