Business rule for populating the hiring manager from the employee ID for catalog item

Vdixt
Tera Expert
(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr = new GlideRecord('sys_user');
gr.addQuery('employee_number',current.variable.manager_employee_number); 
gr.query();

if(gr.next()){
{

current.variable.hiring_manager= current.gr.sys_id;
current.update();

}
}
})(current, previous);

Manager employee number is a string variable and I am trying to populate the hiring manager field. so This catalog item is getting generated from integration they are sending us the employee number and we have to populate the hiring manager from that number. 

1 ACCEPTED SOLUTION

Thanks Hemanth for your reply.

 

I fixed my code and it's working now.

Here is the updated code.

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr = new GlideRecord('sys_user');
gr.addQuery('employee_number',current.variables.manager_employee_number); 
gs.info("Manager number "+" "+current.variables.manager_employee_number);
gr.query();

if(gr.next()){
{

current.variables.hiring_manager= gr.sys_id;


}
}
})(current, previous);

 

 

 

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@Vdixt 

Please share some details

1) BR is on which table? BR configuration screenshots

2) what did you debug

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Vdixt
Tera Expert

Hey Ankur,

The business rule is on SC_req_item table 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr = new GlideRecord('sys_user');
gr.addQuery('employee_number',current.variables.manager_employee_number); 
gs.info("Manager number "+" "+current.variables.manager_employee_number)
gr.query();

if(gr.next()){
{

 current.variables.hiring_manager= current.gr.sys_id;
current.update();

}
}
})(current, previous);

 

Vdixt_0-1697117636946.png

 

Hi @Vdixt ,

I could see u r using before insert BR with current.update don’t use current.update during before insert/update .


how are you creating this request in scripted rest api? Using cart api?

why can’t we set hiring manager during insert in scripted rest api

However try after insert BR once keeping the same logic.

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Thanks Hemanth for your reply.

 

I fixed my code and it's working now.

Here is the updated code.

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr = new GlideRecord('sys_user');
gr.addQuery('employee_number',current.variables.manager_employee_number); 
gs.info("Manager number "+" "+current.variables.manager_employee_number);
gr.query();

if(gr.next()){
{

current.variables.hiring_manager= gr.sys_id;


}
}
})(current, previous);

 

 

 

Hi @Vdixt ,

 

pls close the loop by accepting the solution if it resolved your issue.

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025