- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 12:38 AM
Hello Everyone , I want to write a background script to print last 5 incidents created yesterday and also we have to implement it only using background script. Anyone has any solution? Thanks in advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 12:09 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 09:50 PM
Hi @Akshat8 How are you ?
I am pasting my code please have a look.
var gr=new GlideRecord('incident');
gr.addEncodedQuery('sys_created_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()');
gr.orderByDesc('sys_created_on');
gr.setLimit(5);
gr.query();
while(gr.next())
{
gs.print("The Incident Number is "+gr.number);
}
If my solution helps you please mark my Solution Accepted and Helpful.
Thanks and regards
Uday Kumar Valapudasu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 12:09 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 11:07 PM
Thank you so much for the help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2023 10:46 PM
yw🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 09:00 PM
Hi @Akshat8 ,
Try to use below script for your requirement.
var inc=new GlideRecord('incident');
inc.addEncodedQuery('sys_created_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()');
inc.orderByDesc('sys_created_on');
inc.setLimit(5);
while(inc.next()){
gs.print(inc.number);
}
Thanks,
Gopi