Print 10 latest active incidents

trtrtrtrtrtrtrt
Mega Contributor

Print 10 latest active incidents

4 REPLIES 4

Nivedita Patil
Mega Sage
Mega Sage

Hi @trtrtrtrtrtrtrt ,

Please refer the below link.

https://www.servicenow.com/community/itsm-forum/how-to-get-first-10-active-records-in-incident-table...

 

Mark my answer as accepted solution and helpful if helps you.

 

Thanks,

Nivedita Patil.

shyamkumar VK
Kilo Patron

@trtrtrtrtrtrtrt  ,Please use below Script 

 

var incRecord = new GlideRecord('incident');
incRecord.orderByDesc('sys_created_on');
incRecord.setLimit(10);
incRecord.query();
while(incRecord.next()){
gs.info("Incident Record: " + incRecord.number);

}

 

Regards,

Shyamkumar 

 

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar

Sandeep Rajput
Tera Patron
Tera Patron

@trtrtrtrtrtrtrt Here is the script for you.

var list = new GlideRecord("incident");
list.addActiveQuery();//Get only active records
list.orderByDesc('sys_created_on');//order by created date (used Desc to show latest first);
list.setLimit(10); //Limit the records to 10
list.query();
while (list.next()){
    gs.info(list.getValue('number'));//Prints incident number
}

Hope this helps.

Aniket Chavan
Tera Sage
Tera Sage

Hello @trtrtrtrtrtrtrt ,

Please use the code below.

var grINC = new GlideRecord('incident');
grINC.addActiveQuery(); // Get only active records
grINC.orderByDesc('sys_created_on'); // Order by created date (latest first)
grINC.setLimit(10); // Limit the records to 10
grINC.query();

while (grINC.next()) {
    gs.info("Incident Record: " + grINC.number);
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket