The CreatorCon Call for Content is officially open! Get started here.

in script include how to get the list of users for whom the logged in user is manager

Pravallika9
Tera Expert

A is manager of B and B is manager of C.

then C should be able to see the B and A list.

and B should only see the A list.

how to get that list...in script include i want...because i am going to apply it as a dynamic filter to achieve it in report

6 REPLIES 6

Hi, I want it as a hierarchy level of managers....It works for single level....If the flow is n it wont. Thanx for reply...Can you suggest for n level

AishwaryaS
Tera Contributor
You can refer the below code snippet:
 
 
var UserListScriptInclude = Class.create();
 
UserListScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 
    // Function to get a list of active users
    getActiveUsers: function() {
        var userList = [];
        var userRecord = new GlideRecord('sys_user');
        userRecord.addQuery('manager', gs.getUserID()); // Add conditions based on your requirements
        userRecord.query();
 
        while (userRecord.next()) {
            var userDetails = {
                userId: userRecord.getUniqueValue(),
                userName: userRecord.user_name.toString(),
                fullName: userRecord.getDisplayValue(),
manager: userRecord.manager.getDisplayValue(),
//manager: userRecord.manager.toString(),
                email: userRecord.email.toString(),
                // Add more fields as needed
            };
 
            userList.push(userDetails);
        }
 
        return userList;
    },
 
    // For testing purposes - you can call this function to get a list of active users
    testGetActiveUsers: function() {
        var activeUsers = this.getActiveUsers();
        gs.info(JSON.stringify(activeUsers, null, 4));
    },
 
    type: 'UserListScriptInclude'
});