- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2020 07:26 AM
Hi All,
I wanted to get last 10 records in incident table through background script.
Please help me out here.
Thanks & Regards,
sAtyA.
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2021 11:26 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2020 07:38 AM
Try below script:
var inc = new GlideRecord('incident');
inc.setLimit(10);
inc.orderByDesc('sys_created_on');
inc.query();
while(inc.next()){
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2020 08:12 AM
Hi Satya,
if you want last 10 records which got updated then use this
try{
var incRec = new GlideRecord('incident');
incRec.orderByDesc('sys_updated_on');
// if you want last 10 records which are created then use orderByDesc('sys_created_on')
incRec.setLimit(10);
incRec.query();
while(incRec.next()){
// do processing
}
}
catch(ex){
gs.info('Exception is: ' + ex);
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2020 11:10 PM
Hope you are doing good.
Did my reply answer your question?
If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.
Thanks!
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2021 07:19 AM
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.category);
}