
- 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
05-30-2017 01:42 PM
What's data type of u_mr_print_job field?
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2017 03:48 PM
It is a string and not a reference. The u_click_rate is currency. I wish to find find a record in the table u_mr_print_shop_items with the text "book", then pull the u_click_rate from the same/matching record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2017 01:43 PM
Hello Bob,
Is u_mr_print_job a reference field?
Note: As a best practice I would suggest you to do this via GlideAjax. Please refer below link for more info.
http://wiki.servicenow.com/index.php?title=GlideAjax#gsc.tab=0

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2017 03:51 PM
It is a string and not a reference. I had thought about using GlideAjax but I'm do not find the information clear and simple enough on the wiki to explain what I need to do. from my reply above: I wish to find find a record in the table u_mr_print_shop_items with the text "book", then pull the u_click_rate field data from the same/matching record.