- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 11:04 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2024 06:38 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 12:38 AM
Hi @si21
This is the background script that will fulfill your requirements. You just need to make slight changes and it will work for you.
var userArr=[];
var grSysUser = new GlideRecord('sys_user');
grSysUser.addEncodedQuery("manager=6816f79cc0a8016401c5a33be04be441"); //pass the sysid of the logged in user
grSysUser.query();
while (grSysUser.next()) {
userArr.push(grSysUser.getValue('sys_id'));
}
var splitted_value = userArr.toString().split(',');
for(var count = 0 ; count<splitted_value.length ; count++){
var grSysUser1 = new GlideRecord('sys_user');
grSysUser1.addEncodedQuery("manager.sys_id="+splitted_value[count]);
grSysUser1.query();
while (grSysUser1.next()) {
userArr.push(grSysUser1.getValue('sys_id'));
}
}
gs.print(userArr.toString());
Please mark this as helpful and accept it as a solution if this works for you.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 01:12 AM
Hi @si21
Please follow the below approach :
1. Create a Script Include as below :
var GetReportees = Class.create();
GetReportees.prototype = {
initialize: function() {},
getAssociates: function(user) {
var reportees = [];
var userGr = new GlideRecord('sys_user');
var managerGr = new GlideRecord('sys_user');
userGr.addQuery('manager', user);
userGr.query();
while (userGr.next()) {
reportees.push(userGr.sys_id.toString());
var userSysID = userGr.sys_id;
managerGr.addQuery('manager', userSysID);
managerGr.query();
gs.info(userSysID);
gs.info(managerGr.getRowCount());
var rowCount = managerGr.getRowCount();
if (rowCount != '0') {
gs.info(userGr.getRowCount());
while(managerGr.next()); {
reportees.push(managerGr.sys_id.toString());
}
}
}
//gs.info(reportees.toString());
return 'sys_idIN'+reportees;
},
type: 'GetReportees'
};
2. Make use of below Advanced Reference Qualifier in your Requested for Variable :
javascript: new GetReportees().getAssociates(gs.getUserID());
Output :
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2024 06:00 AM
Hi @Amit Verma ,
Thanks for your response, the code you gave is working for direct reportees only.
Currently Manager is able to see their direct 4 reportees but cannot see reportee's reportees.
Ex. Currently with above code, Abraham lincoln is able to see only his direct reportees. Since Abel tuter is also manager for Alejandra, Abraham lincoln should see 5 members as his reportees including Alejandra.
Please refer below image.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2024 06:38 AM
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.