Populate Employee details based on Employee id

Rekha Tiwari
Kilo Guru

Hi All,

I have a custom table. In which I have created a field called Employee name which is referring to sys_user table and from user table I have called other fields using dot walk as Employee Number, Country, LOcation which is auto populating from user profile

 find_real_file.png

But now client want user should enter employee id then other fields should be auto populated. I have written below BR on that custom table (sn_hr_core_id):

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var gr = new GlideRecord("sys_user");
gr.addQuery('employee_number' , current.u_employee_name.employee_number);
gr.query();
while(gr.next()){
gs.addInfoMessage("1");
current.u_employee_name = gr.name.toString();
current.update();
}

})(current, previous);

but not working. Any suggestion please?

15 REPLIES 15

Hmm, what if I make Employee number a custom field and then map it in transform map?

that should work then but please discuss with your business team about this.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Yes, they want as this only cz they have provided Employee id only.

I have created after/update BR:

(function executeRule(current, previous /*null when async*/ ) { // Add your code here
var gr = new GlideRecord("sys_user");
gr.addQuery('employee_number', current.u_employee_id);
gr.query();
if (gr.next()) {
// gs.addInfoMessage("1");
current.u_employee_name = gr.name.toString();
current.country = gr.country;
current.location = gr.location.toString();
current.update();
}
})(current, previous);

 

When user create record on table by clicking New button, and enter EMployee id then all other values are getting populated as per user profile.

 

But while loading data it is not loading correct data when mapped with  Employee id. All user's detail is empty.

find_real_file.png

Please suggest why so?

Mahesh23
Mega Sage

Hi, Try below code 

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var gr = new GlideRecord("sys_user");
gr.addQuery('employee_number' , current.employee_number);
gr.query();
while(gr.next()){
gs.addInfoMessage("1");
current.u_employee_name = gr.name.toString();
current.update();
}

})(current, previous);

Mahesh23
Mega Sage

Hi,

Are you getting any error or what..?