Using Background script How to get the top 5 close incident records in this year?

Arvind Kumar1
Tera Contributor

Dear all,

Scenario-1:-How to get the top 5 close incident records in this year?

var gr = new GlideRecord('incident');
gr.orderBy('number');
gr.setLimit(5);

gr.query();
while(gr.next())
{
gs.print(gr.number);
}

I had written this script. output was showing but not showing close incident.

Can anyone write correct script?

5 REPLIES 5

Mark Manders
Mega Patron

You didn't include a state = closed in your query, so now it's just all. But what do you mean with 'top 5 close incididents'? You are now only looking at 5 random ones.

If my answer helped you in any way, please then mark it as helpful. If it resolved the issue, please mark it as correct.

Mark


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Maik Skoddow
Tera Patron
Tera Patron

Hi

try this

var gr = new GlideRecord('incident');
gr.orderByDesc('closed_at');
gr.setValue('active', 'false');
gr.setLimit(5);

gr.query();
while(gr.next())
{
gs.print(gr.getValue('number'));
}

Maik

HI for this how would we write script for ,what are the incidents state will be  Resolved by next week ?

HOw would we get it? 

Jaspal Singh
Mega Patron
Mega Patron

Try below

var gr = new GlideRecord('incident');
gr.addQuery('state',3);
gr.orderBy('number');
gr.setLimit(5);

gr.query();
while(gr.next())
{
gs.print(gr.number);
}