Requested for should show manager's reportees and reportee's reportees

si21
Tera Guru

Hi experts,

We have below requirement.

When ever a manager opens 'XYZ record producer' on portal, Requested for variable should display their reportees and If these reportees are managers, their reportees should also be displayed.

 

Ex. If manager 'A' has 3 reportees ( Say P,Q,R) and if P has 3 reportees (say X,Y,Z)  

A should see P,Q,R as well as X,Y,Z

 

How can we achieve this.

TIA

1 ACCEPTED SOLUTION

Hi @si21 

 

Please try with below Script Include :

 

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

    getAssociates: function(user) {
        var reportees = [];
        var userGr = new GlideRecord('sys_user');
        userGr.addQuery('manager.sys_id', user);
        userGr.query();
        while (userGr.next()) {
            reportees.push(userGr.sys_id.toString());
            var userSysID = userGr.sys_id.toString().trim();
			var managerGr = new GlideRecord('sys_user');
			managerGr.addQuery('manager',userSysID);
			managerGr.query();
            var rowCount = managerGr.getRowCount();
            if (rowCount != '0') {
                while(managerGr.next()); {
					reportees.push(managerGr.sys_id.toString());
                }
            }
        }
		return 'sys_idIN'+reportees;
    },

    type: 'GetReportees'
};

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

View solution in original post

5 REPLIES 5

@Amit Verma Thanks a lot for quick  response. It's working fine now.