- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2016 06:44 AM
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);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2016 07:06 AM
Replace g_form.setValue('emp_number', id.field_on_sys_user); with g_form.setValue('emp_number', id.emp_number);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2016 07:09 AM
Default value may also work with this code
- javascript:(function executeRule() {
- var user = new GlideRecord('sys_user');
- if (user.get(current.variables.facility_manager_name) {
- return user.employee_number;
- }
- })();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2016 10:37 AM
Yes , this not the way. Find below script
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading || newValue == ''){
return;
}
var id = g_form.getReference('facility_manager_name');//replace 'u_first_field' with the name of your reference field.
g_form.setValue('emp_number', id.emp_number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2016 10:51 AM
The text 'undefined' is not there initially, but when I populate the 'facility manager name' field, the undefined text displays, and no longer displays the Employee Number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2016 11:01 AM
Hi Nicole,
In Error message itself , its not showing the newly added lines. Please verify that you have pasted the exact script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2016 11:03 AM