I need to populate the email address from the user table.

Archana23
Tera Contributor

I need to populate the email address in the custom table(u_test) from the sys_user table through the employee number as reference. Can anyone help me on the background or fix scripts to achieve the same.

6 REPLIES 6

@Archana23 ,

 

In the above code just modify this line

 

customTableGR.getValue('employee_number');

 

With

 

customTableGR.getValue('GID');

 

Thanks,

Danish

 

Prathamesh G
Kilo Sage
Kilo Sage

Hello @Archana23 ,

 

You can refer to the below code to set the email address on your custom table field referring from the sys_user table.

 

var test = new GlideRecord('u_test'); //your custom table
test.addEncodedQuery('u_employee_number!=NULL'); //use the backend value of the employee number field
test.query();
while (test.next()) {
    var empNumber = test.getDisplayVale('u_employee_number');
    var user = new GlideRecord('sys_user');
    user.addQuery('employee_number', empNumber);
    user.query();
    if (user.next()) {
        test.u_gid = user.email; //use the dot-walk to get the email of the user and set it in the 'GID' 
        test.update();
    }
}

 

If the above solution resolve your issue, Please mark the solution as 'Accepted Solution' and also mark it as 'Helpful'.

 

Thank You!

Prathamesh.