- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 04:18 AM
I want to write a business rule to populate employee Manager name on user ecord, Based on custom added field "manager id" (which is equal to employee number of manager).
could anyone help on this with logic or code - Match manager id with employee number and update that user name under "manager". manager id is the employee number of manager user record. this manager id field is being updated by external script which is mapped with OKTA.
Solved! Go to Solution.
- Labels:
-
Facilities Service Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 04:21 AM
Hi,
Use below business rule. After Insert Update with Condition as Manager Id Changes
Script:
var gr = new GlideRecord('sys_user');
gr.addQuery('employee_number',current.u_manager_id); //employee number is a field where employee id of users are stored and manager id is a field where manager id is stored.
gr.addActiveQuery();
gr.query();
if(gr.next())
{
current.manager = gr.sys_id;
current.update();
}
Thanks,
Ashutosh Munot
Mark answer as helpful or Correct

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 04:21 AM
Hi,
Use below business rule. After Insert Update with Condition as Manager Id Changes
Script:
var gr = new GlideRecord('sys_user');
gr.addQuery('employee_number',current.u_manager_id); //employee number is a field where employee id of users are stored and manager id is a field where manager id is stored.
gr.addActiveQuery();
gr.query();
if(gr.next())
{
current.manager = gr.sys_id;
current.update();
}
Thanks,
Ashutosh Munot
Mark answer as helpful or Correct

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 04:35 AM
This script looks pretty good, but there are a couple of things I would recommend changing.
1) Eliminate 'current.update()' from the script. This will almost always cause you issues with multiple updates running and triggering business rules multiple times.
2) Run your business rule 'before' instead of 'after'. This eliminates the need for the 'current.update()' line.
3) Eliminate the 'addActiveQuery' line. We just want to match the manager ID. It shouldn't matter if the manager is active or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 04:43 AM
Thanks Mark for your inputs. i will embedded the suggested changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 04:41 AM
Thank you very much Ashutosh.
The script worked exactly well. much appreciated for your quick help