Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

i want to get first 10 incidents list

Swathi504893573
Giga Contributor

Hi All,
How can i retrieve the top 10 incident records from the incident table using JS/Glide Record?
For Example, i want to retrieve the 10 most recently created incidents.
Could someone please provide an example script.
Thank you.

3 REPLIES 3

Dr Atul - LNG
Tera Patron

try this

 

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

 

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);

****************************************************************************************
Regards
Dr Atul G. - Learn N Grow Together ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
******************************************************************************************

AntharaS
Kilo Explorer

Hi Swathi,

 

Try this out to retrieve the 10 recently created incident records.

 
var incList = [];
var gr = new GlideRecord('incident');
gr.orderByDesc('sys_created_on');
gr.setLimit(10);
gr.query();
while (gr.next()) {
    incList += ' ' + gr.number;
}
gs.info("Incidents retrieved " + incList);
 
If the solution worked for you, please mark the reply as Helpful. Cheers!😊

Sandeep Rajput
Tera Patron

@Swathi504893573 Here is the script.

 

var gr = new GlideRecord('incident');
gr.orderByDesc('sys_created_on'); 
gr.setLimit(10);
gr.query();
while (gr.next()) {
    gs.info(gr.number); //Print incident number
}