Accessing record fields in a GlideRecord

Bob20
Tera Contributor

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.

1 ACCEPTED SOLUTION

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.

View solution in original post

11 REPLIES 11

sachin_namjoshi
Kilo Patron
Kilo Patron

What's data type of   u_mr_print_job field?



Regards,


Sachin



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.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

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


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.