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-06-2012 12:07 PM
that looks like general code so I can't tell you what may be wrong with it, but your approach is correct. If you alert(FieldTable.getRowCount()); you can at least see if any rows are returned which may help debug it. You may also want to alert(field1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2012 12:33 PM
Hi Chris - thanks for your response. I am actually new to this and I have no idea how to set the row count to see if any rows are returned. 😞

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2012 12:53 PM
function onChange() {
var field1 = g_form.getValue('chair');
if(field1 == '') return false;
alert("field1: " + field1);
var FieldTable = new GlideRecord('table_name');
FieldTable.addQuery('field_name',field1);
FieldTable.query();
alert("rowCount: " + fieldTable.getRowCount());
if(FieldTable.next()){
g_form.setValue('newfield',FieldTable.field2);
}
}
if you get this working, I would suggest NOT doing a client side GlideRecord query, but actually using AJAX. That is more advanced, however, and I understand that you need to get stuff done.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2012 01:07 PM
I updated the script to include the alert and row count, but I only get the alert which shows me the sys_id of the field I am searching on....after I get an error with the script and nothing is updated.
I have attached the alert here just in case you want to see what I mean. -- Thanks.