How to automatically change Opened For for HR Case when the manager of the subject person changes?

Bruno Fernande3
ServiceNow Employee
ServiceNow Employee

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

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@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.

 

Screenshot 2024-02-08 at 10.22.23 PM.png

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.

 

Screenshot 2024-02-08 at 10.24.45 PM.png

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

View solution in original post

1 REPLY 1

Sandeep Rajput
Tera Patron
Tera Patron

@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.

 

Screenshot 2024-02-08 at 10.22.23 PM.png

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.

 

Screenshot 2024-02-08 at 10.24.45 PM.png

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