- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 10:07 AM
Hi experts,
there is a custom field called 'Mgr' on HR profile.
whenever a manager is addedt, changed or removed to a User record. On the manger's HR profile, the custom field should be made true when added and False when manager is removed from user record.
How can we achieve this?
TIA
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 07:40 AM
Instead of checking if a person is manager or not via a checkbox, you can check it via a method in a Script include using GlideAggregate. Here is the script.
function checkManager(user_sys_id){
var managerUser = new GlideAggregate('sys_user');
managerUser.addQuery('manager',user_sys_id);
managerUser.addAggregate('COUNT');
managerUser.query();
var managerCount = 0;
if(managerUser.next()){
managerCount=managerUser.getAggregate('COUNT');
}
return managerCount;
}
gs.info(checkManager('46c6f9efa9fe198101ddf5eed9adf6e7')); //replace this with sys_id of a user
If this script returns a count 0 which indicates the user is not a manager user, if it returns a count more than 0 which means user is a manager user.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 10:47 AM
@si21 This can be simply achieved by creating an onBefore insert update business rule on sys_user table with condition manager changes.
In the business rule script, compare the current.manager and previous.manager values and check if the manager was added/updated/removed.
If the manager is added then you can pick the manager reference from the current.manager field, make a GlideRecord query to sn_hr_core_profile table with query condition addQuery('user', current.manager); once the record is found you can set the Mgr field to true.
Similarly, if the manager is updated, you can follow the above step and uncheck the Mgr checkbox from the previous manager and check it on the new manager. If the manager is removed, simply pick the manager value from the previous.manager and uncheck the Mgr field on the HR profile following the step mentioned above.
Though the scenario you mentioned is perfectly achievable but I see a downside to it as a manager may have more than one reportees assigned to them and setting the Mgr value on the basis of change in manager for a single user may turn out to be an ambiguous approach. I recommend you to rethink your approach here.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 07:05 AM
Hi @Sandeep Rajput , Thanks for you inputs.
"Though the scenario you mentioned is perfectly achievable but I see a downside to it as a manager may have more than one reportees assigned to them and setting the Mgr value on the basis of change in manager for a single user may turn out to be an ambiguous approach. I recommend you to rethink your approach here."
Could you please suggest a better approach in this case. I'm not understanding how to deal with this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 07:40 AM
Instead of checking if a person is manager or not via a checkbox, you can check it via a method in a Script include using GlideAggregate. Here is the script.
function checkManager(user_sys_id){
var managerUser = new GlideAggregate('sys_user');
managerUser.addQuery('manager',user_sys_id);
managerUser.addAggregate('COUNT');
managerUser.query();
var managerCount = 0;
if(managerUser.next()){
managerCount=managerUser.getAggregate('COUNT');
}
return managerCount;
}
gs.info(checkManager('46c6f9efa9fe198101ddf5eed9adf6e7')); //replace this with sys_id of a user
If this script returns a count 0 which indicates the user is not a manager user, if it returns a count more than 0 which means user is a manager user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2023 05:45 AM
Hi @Sandeep Rajput , I have used the above script in BR to update the custom checkbox field on HR profile. It is making the custom field true when user is added as manager but when manager is removed the code is not making the custom field false.
Expected scenario is when manager is removed, BR should check if that user is manager for any other user or not and update the custom field.
Could you please check this code and suggest me the corrections.