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

svirkar420
Kilo Sage

@Swathi504893573 , 
var inc = new GlideRecord('incident');

inc.orderByDesc('sys_created_on');

 inc.setLimit(10);

inc.query();

while (inc.next())

{

gs.info('Incident Number: ' + inc.number + ' | Created: ' + inc.sys_created_on);

}

Tejas Adhalrao
Mega Sage

hi @Swathi504893573  ,

You can use orderByDesc() with setLimit(10).

Example:

var gr = new GlideRecord('incident');
gr.orderByDesc('sys_created_on');
gr.setLimit(10);
gr.query();

while (gr.next()) {
gs.info(gr.getValue('number') + ' - ' + gr.getValue('sys_created_on'));
}

This will return the 10 most recently created incidents.

 

If this helps, please mark it as Helpful and accept the solution.
Regards,
Tejas

Aditya_hublikar
Giga Sage

Hello @Swathi504893573 ,

 

You can refer this :

Aditya_hublikar_0-1791288714617.png

 

If this helps you then mark it as helpful and accept as solution.

Regards,

Aditya

var gr=new GlideRecord('incident');
gr.setLimit(10);

gr.orderByDesc('sys_created_on');
gr.query();
while(gr.next())
{
	
	gs.print('Number :'+gr.number)
}