I need add two condition from Script inculde

Siva82
Tera Expert

 

Hi Team,

 

I need in requested for variables for the users of the manager (the manager is the current logged-in user) and ensure that two group members can view all users (no restrictions for these two groups).

Currently, I have done the manager's users, but in this script, I need to add no restrictions for the two group members. How can I achieve this?

Please check the script and include the reference qualifier.

 

var UserUtils = Class.create();
UserUtils.prototype = {
    initialize: function() {},

    getAllReportees: function(managerSysId) {
        var allReports = [];
        // Start collecting from the given manager
        this.collectReports(managerSysId, allReports);
        return allReports.toString();
    },

    // Recursive function to collect reports
    collectReports: function(managerId, allReports) {
        var directReports = this.getDirectReports(managerId);
        while (directReports.next()) {
            allReports.push(directReports.sys_id.toString());
            this.collectReports(directReports.sys_id, allReports); // Recursively collect indirect reports
        }
    },

    // Function to get direct reports
    getDirectReports: function(managerId) {
        var gr = new GlideRecord('sys_user');
        gr.addQuery('manager', managerId);
        gr.query();
        return gr;
    },

    type: 'UserUtils'
};

Refrence qualfer:

javascript: 'sys_idIN' + new UserUtils().getAllReportees(gs.getUserID());

Thank you in adavcanves
Sivananda Reddy 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Siva82 

try this

If logged in user is member of Group 1 or Group 2 then no restriction, they can see all users

If logged in user is not member of Group 1 and not member of Group 2 then your existing ref qualifier will restrict

javascript: var query; if(gs.getUser().isMemberOf('Group 1') || gs.getUser().isMemberOf('Group 2')) query = ''; else query = 'sys_idIN' + new UserUtils().getAllReportees(gs.getUserID()); query;

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Siva82 

try this

If logged in user is member of Group 1 or Group 2 then no restriction, they can see all users

If logged in user is not member of Group 1 and not member of Group 2 then your existing ref qualifier will restrict

javascript: var query; if(gs.getUser().isMemberOf('Group 1') || gs.getUser().isMemberOf('Group 2')) query = ''; else query = 'sys_idIN' + new UserUtils().getAllReportees(gs.getUserID()); query;

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

Hi @Ankur Bawiskar 

 

Greate It's works. Thank you for your valueble help.