Skip to content

Commit 043ec22

Browse files
authored
Create Delete Incident which are old
This script is designed to run in the **Scripts - Background** module of ServiceNow. It identifies and deletes Incident records that were opened more than 90 days ago from the current date.
1 parent f9a60bc commit 043ec22

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(function() {
2+
var ninetyDaysAgo = new GlideDateTime();
3+
ninetyDaysAgo.subtract(1000 * 60 * 60 * 24 * 90); // 90 days in milliseconds
4+
5+
var gr = new GlideRecord('incident');
6+
gr.addQuery('opened_at', '<', ninetyDaysAgo);
7+
gr.query();
8+
9+
var count = 0;
10+
while (gr.next()) {
11+
gs.info('Deleting Incident: ' + gr.number);
12+
gr.deleteRecord();
13+
count++;
14+
}
15+
16+
gs.info('Total Incidents Deleted: ' + count);
17+
})();

0 commit comments

Comments
 (0)