Calling script include in condition filter to get the sys id of users

sasharma815
Tera Contributor

I have made a  script include which is returning all the users that logged in user is manager of i want to use this script include in my reports filter condition which is on a database view table somehow i am getting sys id is null when i call script include in filter condition can anyone tell me  what is wrong i am doing here or what can be a possible solution for this 

 

 

sasharma815_0-1757936431174.png

 

sasharma815_1-1757936455413.png

 

1 REPLY 1

M Iftikhar
Mega Sage

Hi @sasharma815

 

The function getUserOfManager accepts a userSysId as a parameter. However, inside the function, it completely ignores this parameter and instead uses gs.userID() as you can see in this part of your code:

// Incorrect code
if (gr.get(gs.userID())) { 
  mgr = gr.getValue('manager');
}

This means the script always finds the manager of the currently logged-in user, not the user whose sys_id was passed to the function.

 

Also script include is named getGroupManager and the method is getUserOfManager. The code does not get a manager; it finds all the subordinate users who report up to a specific manager. A more accurate name would be getReportingHierarchy or getAllSubordinates.

 

The recursive design is functional, but if there is a loop in your user data (e.g., User A's manager is B, and User B's manager is A), this script will run indefinitely until the transaction is canceled for exceeding the execution quota.

 

Try fixing these issues then maybe your script would work!

 

Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution and helpful so others can benefit as well.