- 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-30-2023 11:19 PM
@si21 You need to revise the implementation slightly, whenever a person is added/updated on a user record as a manager in the manager field, you can always set the value of u_is_manager to true without even checking the count. However, whenever the manager is removed from the manager field on a record, you will find that value in previous object in the business rule.
Updated your BR as follows.
(function executeRule(current, previous /*null when async*/ ) {
if (current.manager != '' && current.manager.u_is_manager == false) {
var glideManager = new GlideRecord('sys_user');
if (glideManager.get(current.manager.sys_id)) {
glideManager.setValue('u_is_manager', true);
glideManager.setWorkflow(false);
glideManager.update();
}
}
if (previous.manager != '') {
// Add your code here
var managerUser = new GlideAggregate('sys_user');
managerUser.addQuery('manager', previous.manager);
managerUser.addAggregate('COUNT');
managerUser.query();
var managerCount = 0;
if (managerUser.next()) {
managerCount = managerUser.getAggregate('COUNT');
if (managerCount == 0) {
var glideOldManager = new GlideRecord('sys_user');
if (glideOldManager.get(previous.manager.sys_id)) {
glideOldManager.setValue('u_is_manager', false);
glideOldManager.setWorkflow(false);
glideOldManager.update();
}
}
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 04:28 AM
Hi @Sandeep Rajput , I think I was not clear in the earlier reply, this custom field 'u_is_manager' is on HR profile table [sn_hr_core_profile] not on User table. When a user is added/removed as manager, their HR profile's custom field 'u_is_manager' needs to be updated. Could you please help me. Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 04:55 AM
@si21 Instead of creating the BR on sys_user, you can create in on sn_hr_core_profile and use the same logic there.