- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 10:13 AM
(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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 11:37 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 06:31 AM
Please share some details
1) BR is on which table? BR configuration screenshots
2) what did you debug
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 06:35 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 11:19 AM
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.
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 11:37 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 05:53 PM
Hi @Vdixt ,
pls close the loop by accepting the solution if it resolved your issue.
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025