How can I auto populate an employee ID based on the selected user?

nicolemccray
Tera Expert

I have a variable titled 'Facility Manager Name' (facility_manager_name) which is a reference field that allows the requester to look up and select a person.   I would like to auto populate the 'Employee Number' (emp_number) field based on the person selected.   I have tried the following Client Script, but I am doing something wrong:

function onChange(control, oldValue, newValue, isLoading) {  

var id = g_form.getValue('facility_manager_name');//replace 'u_first_field' with the name of your reference field.  

var user = new GlideRecord('sys_user');  

          user.addQuery('sys_id',id);  

          user.query();  

if ( user.next() ) {    

  g_form.setValue('emp_number', user.field_on_sys_user);  

}  

}

1 ACCEPTED SOLUTION

Replace g_form.setValue('emp_number', id.field_on_sys_user); with   g_form.setValue('emp_number', id.emp_number);


View solution in original post

15 REPLIES 15

Ok, I've got it working.   Thank you so much for your help!!!