- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2016 02:42 AM
Friends,
I am running below background script. As shown in output, count is 1 but number returned is "undefined". Please help me in getting the correct number?
var abc = new GlideRecord('change_task');
abc.addQuery('number', 'CTASK0023280');
abc.query();
var count=abc.getRowCount();
//gs.log('Parent is '+ abc.sys_id);
gs.log('count is '+count);
gs.print('Number is ' + abc.number);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[0:00:00.006] Script completed in scope global: script
*** Script: count is 1
*** Script: Number is undefined
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2016 02:46 AM
you need to iterate the table after querying.
var abc = new GlideRecord('change_task');
abc.addQuery('number', 'CTASK0023280');
abc.query();
var count=abc.getRowCount();
//gs.log('Parent is '+ abc.sys_id);
gs.log('count is '+count);
while(abc.next())
{
gs.print('Number is ' + abc.number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2016 02:46 AM
you need to iterate the table after querying.
var abc = new GlideRecord('change_task');
abc.addQuery('number', 'CTASK0023280');
abc.query();
var count=abc.getRowCount();
//gs.log('Parent is '+ abc.sys_id);
gs.log('count is '+count);
while(abc.next())
{
gs.print('Number is ' + abc.number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2016 02:47 AM
add a line: abc.next();
var abc = new GlideRecord('change_task');
abc.addQuery('number', 'CTASK0023280');
abc.query();
abc.next();
var count=abc.getRowCount();
//gs.log('Parent is '+ abc.sys_id);
gs.log('count is '+count);
gs.print('Number is ' + abc.number);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2016 02:48 AM
you missed abc.next() buddy!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2016 02:50 AM
Hi,
After var count=abc.getRowCount();
add below:
if(abc.next())
{
gs.log('count is '+count);
gs.print('Number is ' + abc.number);
}