i want to get first 10 incidents list

Swathi504893573
Tera 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.

7 REPLIES 7

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
Mega Contributor

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
}

Tanushree Maiti
Tera Patron

Hi @Swathi504893573 

 

Here is script for 10 most recently created INCs

 

var incGr = new GlideRecord('incident');
incGr.orderByDesc('sys_created_on');
incGr.setLimit(10);
incGr.query();
while(incGr.next())
{
gs.info("Incident Records--> " + incGr.number);
}

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti