Skip to content

Commit 63a6c93

Browse files
authored
Create Readme.md
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 043ec22 commit 63a6c93

File tree

1 file changed

+28
-0
lines changed
  • Server-Side Components/Background Scripts/Old Incident

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Delete Incidents Older Than 90 Days – ServiceNow Script
2+
3+
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.
4+
5+
## 🧩 Purpose
6+
7+
To clean up old Incident records that are no longer relevant or needed, helping maintain a lean and efficient ServiceNow instance.
8+
9+
## 🛠️ Script Overview
10+
11+
12+
(function() {
13+
var ninetyDaysAgo = new GlideDateTime();
14+
ninetyDaysAgo.subtract(1000 * 60 * 60 * 24 * 90); // 90 days in milliseconds
15+
16+
var gr = new GlideRecord('incident');
17+
gr.addQuery('opened_at', '<', ninetyDaysAgo);
18+
gr.query();
19+
20+
var count = 0;
21+
while (gr.next()) {
22+
gs.info('Deleting Incident: ' + gr.number);
23+
gr.deleteRecord();
24+
count++;
25+
}
26+
27+
gs.info('Total Incidents Deleted: ' + count);
28+
})();

0 commit comments

Comments
 (0)