- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 08:39 AM
I am doing a lookup to a table to populate a field and this is working but when i remove the value (lines 5 and 6) the field doesnt clear to blank the field i am trying to set to blank is a date field if that maters. It doesnt seem that when the field data is removed the client script runs.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue == ''){
g_form.setValue('u_foobar','');
}
var gs = new GlideRecord('u_table');
gs.addQuery('sys_id',newValue);
gs.query();
if (gs.next()) {
g_form.setValue('foobar',gs.foobar);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 08:40 AM
Line 2 is returning if the value is blank. Make line 2 only say "if (isLoading) {"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 08:40 AM
Line 2 is returning if the value is blank. Make line 2 only say "if (isLoading) {"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 08:43 AM
On which field the change trigger is on? And I see you using u_foobar, foobar? What is the variable/field name?
Try this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
if (newValue == ''){
g_form.setValue('u_foobar','');
}
return;
}
var gs = new GlideRecord('u_table');
gs.addQuery('sys_id',newValue);
gs.query();
if (gs.next()) {
g_form.setValue('foobar',gs.foobar);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 08:43 AM
Hi,
You most likely want an else so you're not clearing the field then looking it up again (with a newValue of null). I also changed your gs to a gr variable so my eyes didn't pop out of my head thinking you were using a server side GlideSystem object.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue == ''){
g_form.setValue('u_foobar','');
} else {
var gr = new GlideRecord('u_table');
gr.addQuery('sys_id',newValue);
gr.query();
if (gr.next()) {
g_form.setValue('u_foobar',gr.foobar);
}
}
}