Skip to content

Commit 95b40d4

Browse files
authored
Add script to get incident records older than 30 days
This script retrieves records from the 'incident' table that are older than 30 days based on the 'opened_at' field. It limits the output to 200 records and provides a count of the retrieved records.
1 parent c96fc80 commit 95b40d4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Background Script or Script Include method
2+
(function() {
3+
var TABLE = 'incident'; // table to query
4+
var FIELD = 'opened_at'; // date-time field to compare
5+
var DAYS = 30; // older than N days
6+
7+
var gdt = new GlideDateTime();
8+
gdt.addDaysUTC(-DAYS); // move back N days in UTC
9+
10+
var gr = new GlideRecord(TABLE);
11+
gr.addQuery(FIELD, '<=', gdt.getValue()); // index-friendly comparison
12+
gr.addActiveQuery(); // example extra filter
13+
gr.setLimit(200); // sample to avoid huge output
14+
gr.query();
15+
16+
var count = 0;
17+
while (gr.next()) {
18+
count++;
19+
// do work or collect ids
20+
// gs.info(gr.getUniqueValue() + ' | ' + gr.getDisplayValue(FIELD));
21+
}
22+
23+
gs.info(TABLE + ' older than ' + DAYS + ' days: ' + count);
24+
})();

0 commit comments

Comments
 (0)