
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 08:40 AM
If the manager of an employee changes after the HR Case is submitted, is there a way to automatically update all "opened for" HR Cases with the new manager?
Are there any best practices for this?
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 08:57 AM
@Bruno Fernande3 This can be achieved by writing a business rule on sys_user table with a condition manager changes and Manager is not empty.
In the script, you need to query sn_hr_core_case table to check if there are any open cases where the current user is subject person and the pervious manager is opened for.
Update the opened for field with the new manager. Here is the script.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var glideHRCase = new GlideRecord('sn_hr_core_case');
glideHRCase.addActiveQuery();
glideHRCase.addQuery('subject_persin',current.sys_id);
glideHRCase.addQuery('opened_for',previous.manager);
glideHRCase.query();
while(glideHRCase.next()){
glideHRCase.setValue('opened_for',current.manager);
glideHRCase.update();
}
})(current, previous);
Hope this helps.
Inside the script, you need to query the sn_hr_core_case table with a filter

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 08:57 AM
@Bruno Fernande3 This can be achieved by writing a business rule on sys_user table with a condition manager changes and Manager is not empty.
In the script, you need to query sn_hr_core_case table to check if there are any open cases where the current user is subject person and the pervious manager is opened for.
Update the opened for field with the new manager. Here is the script.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var glideHRCase = new GlideRecord('sn_hr_core_case');
glideHRCase.addActiveQuery();
glideHRCase.addQuery('subject_persin',current.sys_id);
glideHRCase.addQuery('opened_for',previous.manager);
glideHRCase.query();
while(glideHRCase.next()){
glideHRCase.setValue('opened_for',current.manager);
glideHRCase.update();
}
})(current, previous);
Hope this helps.
Inside the script, you need to query the sn_hr_core_case table with a filter