Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to get first 10 Active records in incident table

Harsha varma
Kilo Explorer

Hi am new to ServiceNow please help to code

8 REPLIES 8

manu7867
Tera Contributor

Hi Harsha,

please check this

var gr=newGlideRecord('incident');
gr.addQuery('active','true');
gr.setLimit('10');
gr.query();
while(gr.next()){
gs.print(number);

}

manu7867
Tera Contributor

var gr=newGlideRecord('incident');
gr.addQuery('active','true');
gr.setLimit('10');
gr.query();
while(gr.next()){
gs.print(gr.number);

}

Raghu Ram Y
Kilo Sage

Hi,

Use the below code to get 10 active incidents.

var gr = new GlideRecord('incident');
gr.addQuery('active','true');
gr.orderByDesc('sys_created_on');
gr.setLimit(10);
gr.query();
while(gr.next())
{
gs.print(gr.number);
}

Hope it helps, please mark my response as correct and helpful.

Hi Raghu Ram Y,

I understood the script but where to execute it, such as on client script or UI Policy or business rule, script include as we want to show incidents in list view.