last X days incidents
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2022 02:19 AM
how can i get last x days incidents in background scripts.
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2022 02:30 AM
@sravankumar9637 Please write below code in background script
var numberOfDays = 10;
var inc = new GlideRecord("incident");
inc.addQuery("sys_created_onRELATIVELT@dayofweek@ahead@"+numberOfDays);
inc.query();
while(inc.next()){
gs.info(inc.number.toString());
}
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023
ServiceNow Community Rising Star, Class of 2023
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2022 02:57 AM
ok fine nice , But how to get without encoded Query
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2022 03:00 AM
@sravankumar9637 Without encoded query means?
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023
ServiceNow Community Rising Star, Class of 2023
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2022 02:32 AM
Here's an example script you can use (obviously doing whatever you'd like in the while loop):
var daysAgo = 7; // update accordingly
var latestIncidents = new GlideRecord('incident');
latestIncidents.addEncodedQuery('sys_created_onRELATIVEGT@dayofweek@ago@' + daysAgo.toString());
latestIncidents.query();
while(latestIncidents.next()) {
gs.print(latestIncidents.getValue('number'));
}