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

Hemanth M1
Giga Sage
Giga Sage

Hi @Vdixt ,

 

Use variables instead variable

like :

addQueryline - current.variables.manager_employee_number

update line :    current.variables.hiring_manager= current.gr.sys_id;

 

 

 

Accept and hit Helpful if it helps.

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

Thanks Hemanth for your response.

 

but still the hiring manager field is still not populating.

Hi @Vdixt ,

 

When does this BR runs???, Need to understand your form variables.

 

check are you getting manager_employee_number by logging it BR.

gs.info("Manager number "+" "+current.variables.manager_employee_number)

Accept and hit Helpful if it helps.

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

Vdixt_0-1697117132027.png

I checked it I am getting the manger employee number, so this request is creating through third party tool, we are using scripted rest API to set the variables, so now they are sending us the  Manager employee  number and we have to populate the hiring manager field after creating the request.