Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to get the last 10 records in incident table?

SN27
Giga Expert

Hi All,

I wanted to get last 10 records in incident table through background script.

Please help me out here.

Thanks & Regards,

sAtyA.

1 ACCEPTED SOLUTION

Himanshu Gupta1
Mega Guru

HI,

Please find the below script for getting last 10 records.

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

}

 

Please mark this helpful if your query is resolved

Best Regards

Himanshu 

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@Satya Yadav 

Hope you are doing good.

Did you get a chance to check on the solution provided to resolve your query?

If your query is resolved please my response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

PRASHANTH KUMAR
Kilo Explorer

try this code

 display business rule

var inc = new GlideRecord('incident');
inc.setLimit(10);
inc.orderByDesc('number');
inc.query();
while(inc.next())
{
gs.addInfoMessage("last 10 records #" + inc.number);
}

Himanshu Gupta1
Mega Guru

HI,

Please find the below script for getting last 10 records.

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

}

 

Please mark this helpful if your query is resolved

Best Regards

Himanshu 

Can this also be written as an Encoded Query or UI Macro?

I got that to work, but how do you translate that over to a UI Macro?