Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to get the last 10 records in incident table

tom_lundy
Kilo Contributor

I am trying to do a get call to retrieve the latest 10 records in a incident table.

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

Hi Tom,



setLimit(): Sets the limit for how many records you want to fetch.



find_real_file.png



var c=0;


var check= new GlideRecord('incident');


check.addQuery('category','software');


check.setLimit(10);


check.query();


while(check.next())


{


c++


gs.print('check the :'+check.number);


}


gs.print('total nnumber of record is:'+c);



OUTPUT



find_real_file.png



http://wiki.servicenow.com/index.php?title=GlideRecord#setLimit


View solution in original post

8 REPLIES 8

harshvardhansingh


Does orderByAsc() worked for you?


Hi Shishir,



yes, i have modified the code and it gives result as number by descending order.




find_real_file.png



Output:



find_real_file.png



Code:



var c=0;


var gr= new GlideRecord('incident');


gr.orderByDesc('sys_created_on');


gr.setLimit(10);


gr.query();


while(gr.next())


{


c++


gs.print('check the :'+gr.number);


}


gs.print('total number of record is:'+c);


Arvind Kumar1
Tera Contributor

var gr = new GlideRecord('incident');

gr.orderBy('number');
gr.setLimit(10);
gr.query();
while(gr.next())
{
gs.print(gr.number);
}

Chiranjeevi K
Tera Expert

Can any one let me know what change should be done to print last 10 records of the current logged in user .