
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2017 01:25 PM
I have table which has three columns and I'm using a form OnChange event to trigger a client script to look for one record, then pull data from another field from the same record and place it on the form.
The code is:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//alert('Click Rate update triggered');
populateJobData();
}
function populateJobData(){
var selected = g_form.getValue('u_mr_print_job'); //user data from the form
//alert('Print item selection: ' + selected);
var pjob = new GlideRecord('u_mr_print_shop_items'); //open the table
alert('GlideRec created');
pjob.addQuery('u_mr_print_service', selected); //find the record
pjob.query();
alert('Query has run');
if (pjob.hasNext()) {
//yes, found it, do it
alert('Record found');
alert('Click Rate: ' + pjob.u_mr_click_rate);
} else {
//no, didn't find it
alert('GlideRec empty');
}
}
The table is u_mr_print_shop_items and the fields are: u_mr_print_service, u_mr_click_rate, u_mr_delivery. I look for a matching record for the u_mr_print_service, then pull out the u_mr_click_rate value. In the code I get an "undefined" value. it's as if the field does not exist. I have looked through the Community but can't seen to find an explanation or solution.
Thanks,
Bob.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2017 04:02 PM
One correction to your code. Try below
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//alert('Click Rate update triggered');
populateJobData();
}
function populateJobData(){
var selected = g_form.getValue('u_mr_print_job'); //user data from the form
//alert('Print item selection: ' + selected);
var pjob = new GlideRecord('u_mr_print_shop_items'); //open the table
alert('GlideRec created');
pjob.addQuery('u_mr_print_service', selected); //find the record
pjob.query();
alert('Query has run');
if (pjob.next()) {
//yes, found it, do it
alert('Record found');
alert('Click Rate: ' + pjob.u_mr_click_rate);
} else {
//no, didn't find it
alert('GlideRec empty');
}
}
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
06-06-2017 01:20 PM
Bob, I know I am late to reply but you may find my getReferenceAdvanced solution useful to solve use cases like these. It doesn't require GlideAjax and it will simplify your client script code too and you won't need GlideRecord any longer.
getReferenceAdvanced, g_form.getReference and GlideAjax Alternatives

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2017 04:01 PM
Michael,
Thanks for that. Looks like a great, and easy way to do that!
B.