How to assign user on a table based on employee number

sony8
Tera Contributor

Hi All,

 

hope you are doing well!!

I have following requirement.

 

Actually we have requestor and employee number variable on my record producer .

 

on my record producer we have below variable coming from the employee reference table

Department, Date of birth, Employee number , Hiring Date and User name(reference field on sys_user table).

 

requestor and employee number are coming from sys_user table

 

Department , Date of birth and Hiring date coming from employee reference table.

 

in both tables employee number is the primary key.

 

 

I want to populate User name field on reference table based on employee number from sys_user table.

 

how to populate user name on employee reference table based on employee number.

2 REPLIES 2

Clara Lemos
Mega Sage
Mega Sage

Hi @sony8 ,

If your intension is to populate the user name filed ( reference field to the sys_user table) based on the employee number that was populated via the record producer, you do the following 🙂 

 Add a Business Rule on your employee reference table.

Add a condition so that it runs after insert/update with a condition that employee number is not empty 

On the advanced tab, add a script like below

(function executeRule(current, previous /*null when async*/ ) {
    var user = new GlideRecord('sys_user');
    user.addQuery('employee_number', current.employee_number);
    user.query();
    if (user.next()) {
        current.u_user = user.sys_id;
        current.update();
    }
})(current, previous);

Please note, where you see 'current.employee_number', you should use current.{the name of the employee number field on your employee reference table). And, where you see 'current.u_user', you should use current.{the name of the user  field on your employee reference table)

 

If that helps please mark my answer as correct / helpful!
And if further help is needed please let me know

Cheers

 

 

 

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @sony8 

 

I am not sure we need to write script , where the Auto populate is available OOTB:

 

 , but if i am not wrong you can use Auto populate method as well. 

Create 2 variable

- User Name ( Reference to user Table)

- Employee Number - Single line text

Go to Auto populate tab. and do dot walk to employee number

LearnNGrowAtul_1-1700911311001.png

 

 

LearnNGrowAtul_2-1700911311054.png

 

 

 

LearnNGrowAtul_3-1700911311025.png

 

**** This example is on different variable, but solution is here. 

 

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************