Getting undefined in logs when using GlideRecord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 11:44 PM
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.
- Labels:
-
Request Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 11:47 PM
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
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 11:48 PM
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
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 12:53 AM
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