- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2022 08:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2022 09:09 AM - edited ‎12-17-2022 09:55 AM
var arr=[];
var inc= new GlideRecord('incident');
inc.orderByDesc('sys_created_on');
inc.setLimit(5);
while(inc.next())
{
arr.push(inc.number.toString());
}
gs.print(arr);
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2022 09:12 AM
@hemasree kanduk use below code
var inc = new GlideRecord ('incident');
inc.orderByDesc('sys_created_on');
inc.setLimit(5);
inc.query();
while (inc.next()){
gs.info(inc.number.toString());
}
Please mark as correct answer if this solves your issue
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2022 09:09 AM - edited ‎12-17-2022 09:55 AM
var arr=[];
var inc= new GlideRecord('incident');
inc.orderByDesc('sys_created_on');
inc.setLimit(5);
while(inc.next())
{
arr.push(inc.number.toString());
}
gs.print(arr);
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2022 09:50 AM
hii raghav thankyou for the response, and the code you have written is not printing the incident numbers in an array. and i didn't understand why you have written this line ...for (var i = 0; i < arr.length; i++)....? instead of that,
i tried this code without that line
var arr=[];
var inc= new GlideRecord('incident');
inc.orderByDesc('sys_created_on');
inc.setLimit(5);
inc.query();
while(inc.next())
{
arr.push(inc.number.toString());
//for (var i = 0; i < arr.length; i++)
}
gs.print(arr);
this code is working fine and returning the latest 5 incidents in an array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2022 09:54 AM - edited ‎12-17-2022 09:56 AM
@hemasree kanduk i thought i passed object in array so i tried a for loop, but in this case gs.print(arr); will work fine, nice catch.
I updated the post accordingly.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2022 09:12 AM
@hemasree kanduk use below code
var inc = new GlideRecord ('incident');
inc.orderByDesc('sys_created_on');
inc.setLimit(5);
inc.query();
while (inc.next()){
gs.info(inc.number.toString());
}
Please mark as correct answer if this solves your issue
ServiceNow Community Rising Star, Class of 2023