- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2025 04:47 AM
Hi team,
I have a variable 'Employee' which is a reference type.
If a manager is viewing form, the 'Employee' variable should show manager's reports and also manager name
If an employee is viewing form and does not have any reports, 'Employee' variable should show the employee name only.
How can I achieve this. Currently I'm able to show reports for manager but how can I also include the manager name
TIA
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2025 05:30 AM
you can use this reference qualifier along with script include
javascript: new EmployeeUtils().getReportsAndManager();
var EmployeeUtils = Class.create();
EmployeeUtils.prototype = {
initialize: function() {},
getReportsAndManager: function() {
var result = [];
var userID = gs.getUserID();
// Check if logged in user is manager of someone
var reportGR = new GlideRecord('sys_user');
reportGR.addQuery('manager', userID);
reportGR.query();
if (reportGR.getRowCount() > 0) {
while (reportGR.next()) {
result.push(reportGR.getUniqueValue());
}
// push manager or logged in user also
result.push(userID);
} else {
// logged in user has no reportee
result.push(userID);
}
return 'sys_idIN' + result.toString();
},
type: 'EmployeeUtils'
};
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2025 05:30 AM
you can use this reference qualifier along with script include
javascript: new EmployeeUtils().getReportsAndManager();
var EmployeeUtils = Class.create();
EmployeeUtils.prototype = {
initialize: function() {},
getReportsAndManager: function() {
var result = [];
var userID = gs.getUserID();
// Check if logged in user is manager of someone
var reportGR = new GlideRecord('sys_user');
reportGR.addQuery('manager', userID);
reportGR.query();
if (reportGR.getRowCount() > 0) {
while (reportGR.next()) {
result.push(reportGR.getUniqueValue());
}
// push manager or logged in user also
result.push(userID);
} else {
// logged in user has no reportee
result.push(userID);
}
return 'sys_idIN' + result.toString();
},
type: 'EmployeeUtils'
};
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader