- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 08:42 AM
Hi all,
I am having doubts regarding one requirement. The requirement is in user criteria the manager should have atleast one employee reported to him and one of the user should have the employee type as EMPL. I have completed the requirement but need ur help to check.
var answer = false;
var currentUser = gs.getUser().getRecord();
answer = (
currentUser.getValue("active") == "1" &&
currentUser.getValue("u_employee_type").toLowerCase() == "empl" &&
_isManager(gs.getUserID())
);
function _isManager(userID) {
var userGA = new GlideRecord("sys_user");
userGA.addQuery("manager", userID);
userGA.addActiveQuery();
userGA.query();
var directreportee = false;
while (userGA.next()) {
directreportee = true;
if (userGA.getValue("u_employee_type").toLowerCase() == 'empl') { //userGA.getAggregate("COUNT")
return true;
}
}
return directreportee;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 09:20 AM
Hi @Abishek1998,
Issue Explanation:
The original code returned true too early inside the while loop, causing the check to fail before validating both conditions: the manager having at least one employee and one employee having type EMPL.
Updated Code Explanation:
var answer = false;
var currentUser = gs.getUser().getRecord();
answer = (
currentUser.getValue("active") == "1" &&
currentUser.getValue("u_employee_type").toLowerCase() == "empl" &&
_isManagerWithEmployee(gs.getUserID())
);
function _isManagerWithEmployee(userID) {
var userGA = new GlideRecord("sys_user");
userGA.addQuery("manager", userID);
userGA.addActiveQuery();
userGA.query();
var hasEmployee = false;
var hasEMPL = false;
while (userGA.next()) {
hasEmployee = true;
if (userGA.getValue("u_employee_type").toLowerCase() == 'empl') {
hasEMPL = true;
}
}
return hasEmployee && hasEMPL;
}
Summary:
This code ensures the manager has at least one employee reporting to them, and that one employee has the type EMPL.
Best regards,
Siddhesh Jadhav
Please mark my answer helpful if it solved your query!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 09:20 AM
Hi @Abishek1998,
Issue Explanation:
The original code returned true too early inside the while loop, causing the check to fail before validating both conditions: the manager having at least one employee and one employee having type EMPL.
Updated Code Explanation:
var answer = false;
var currentUser = gs.getUser().getRecord();
answer = (
currentUser.getValue("active") == "1" &&
currentUser.getValue("u_employee_type").toLowerCase() == "empl" &&
_isManagerWithEmployee(gs.getUserID())
);
function _isManagerWithEmployee(userID) {
var userGA = new GlideRecord("sys_user");
userGA.addQuery("manager", userID);
userGA.addActiveQuery();
userGA.query();
var hasEmployee = false;
var hasEMPL = false;
while (userGA.next()) {
hasEmployee = true;
if (userGA.getValue("u_employee_type").toLowerCase() == 'empl') {
hasEMPL = true;
}
}
return hasEmployee && hasEMPL;
}
Summary:
This code ensures the manager has at least one employee reporting to them, and that one employee has the type EMPL.
Best regards,
Siddhesh Jadhav
Please mark my answer helpful if it solved your query!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2025 02:33 AM - edited 06-11-2025 02:42 AM
var grUser = new GlideRecord("sys_user");
grUser.addQuery("manager", user_id);
grUser.addActiveQuery();
grUser.setLimit(1);
grUser.query();
answer = grUser.hasNext();
add your query for employee type as EMPL