Using Glide script to update a field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2012 10:35 AM
Hi -
I am trying to use a glide record to updated a field based on the selection from another field.
I have a table that has columns:
field1 field2
chair seat
table cloth
Below is that I have and it's not working: :-((
-------------------------------------------------------------
function onChange() {
var field1 = g_form.getValue('chair');
if(field1 == '') return false;
var FieldTable = new GlideRecord('table_name');
FieldTable.addQuery('field_name',field1);
FieldTable.query();
if(FieldTable.next()){
g_form.setValue('newfield',FieldTable.field2);
}
}
-------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2012 09:26 AM
Aha, you're doing a get(). That means you don't need to do a next(). Just do the following (I restructured the script a bit):
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading)
return; // do not run on form load
var machine = g_form.getValue('u_target_ndm_machine');
if (machine == '')
return; // no value or field not on form
var targetMachine = new GlideRecord('u_machine_list');
if (!targetMachine.get(machine))
return; // did not find one
g_form.setValue('u_target_ndm_node', targetMachine.u_ndm_node_name);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2012 10:32 AM
Hi CapaJC -
Your script worked like a CHARM!!! Thank you, thank you, thank you. :-)))))