Getting undefined in logs when using GlideRecord

T_6
Tera Contributor

Hi this is the script to fetch some data from stock table. This script is written inside a function in scheduled job. Here according to me syntax and everything is correct but in logs I am getting ' Hello 9 undefined undefined' So I am not getting why it is giving 'undefined'. Can someone please correct me if I am wrong somewhere?

var x = new GlideRecord('stock');
var xtype = x.type; //reference field
var xvend = x.u_vend; //boolean
x.addQuery(xtype, 'Newly created');
x.addQuery(xvend, true);

//querying
x.query();
gs.log('Hello ' + x.getRowCount() +' '+x.u_vending_id+' '+x.u_location_id);  //x.u_vending_id: String, x.u_location_id: reference

 

Thanks in advance.

3 REPLIES 3

Harish KM
Kilo Patron
Kilo Patron

share the full script.

var x = new GlideRecord('stock');

var xtype = x.type; //reference field

var xvend = x.u_vend; //boolean

x.addQuery(xtype, 'Newly created');

x.addQuery(xvend, true);

//querying

x.query();
while(x.next())
{

gs.log('Hello ' + x.getRowCount() +' '+x.u_vending_id+' '+x.u_location_id);  //x.u_vending_id: String, x.u_location_id: reference
}

Regards
Harish

Abhijit4
Mega Sage

Hi,

You should have x.next() after x.query() line.

Something like below,

var x = new GlideRecord('stock');

var xtype = x.type; //reference field

var xvend = x.u_vend; //boolean

x.addQuery(xtype, 'Newly created');

x.addQuery(xvend, true);

//querying

x.query();
while(x.next())
{
gs.log('Hello ' + x.getRowCount() +' '+x.u_vending_id+' '+x.u_location_id);  //x.u_vending_id: String, x.u_location_id: reference
}

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Namrata Ghorpad
Mega Sage
Mega Sage

Hello,

Try the below code.

var x = new GlideRecord('stock');
var xtype = x.type; //reference field
var xvend = x.u_vend; //boolean
x.addQuery(xtype, 'sys_id of Newely Created ');
x.addQuery(xvend, true);

//querying
x.query();

while(x.next())

{

gs.log('Hello ' + x.getRowCount() +' '+x.u_vending_id+' '+x.u_location_id);  //x.u_vending_id: String, x.u_location_id: reference

}

Thanks,

Namrata