onchange client script to populate fields with values from another table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2018 02:04 PM
on the computer table (cmdb_ci_computer), i need to pull the values from the assigned to table which is a reference field of the sys_user table. If the value changes, i need to reflect those changes.
I am using an onchange client script
Presently, the iocation field is being pulled back but not the department field.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var user = new GlideRecord('sys_user');
user.addQuery('department', newValue);
user.addQuery('location', newValue);
user.query();
if(user.next())
{
var userID = user.sys_id;
g_form.setValue('department', userID);
g_form.setValue('location', userID);
}
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2018 05:56 PM
Hey,
You have to write some thing like below
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading||newValue =='') {
return;
}
if (newValue == 'Pending') {
g_form.setValue('u_requeststatus','Incomplete');
}
}
Hope Incomplete, Pending are back end values not labels, give a try with above code

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2018 06:57 PM
Please use this script. This onChange client script should run on change of assigned to field.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue){
var caller = g_form.getReference('assigned_to', popCallerInfo);
}
function popCallerInfo(caller){
g_form.setValue('location', caller.location);
g_form.setValue('department', caller.department);
}
}
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2018 09:25 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2018 07:12 AM