Skip to content

Commit ea59f67

Browse files
authored
Merge pull request #1983 from bhavyaa30/Archiving-Old-Incident-Records-to-Improve-Performance
Archiving old incident records to improve performance
2 parents 17533e7 + e5753d7 commit ea59f67

File tree

2 files changed

+22
-0
lines changed
  • Core ServiceNow APIs/GlideRecord/Archiving Old Incident Records to Improve Performance

2 files changed

+22
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Purpose
2+
This document explains how to archive old incident records from the `incident` table to an archive table `ar_incident` to improve performance, while preserving historical data for reporting and audit purposes.
3+
## Solution Overview
4+
Use **ServiceNow Archive Rules** to automatically move incidents to an archive table based on specific conditions:
5+
- Incidents that are **closed**.
6+
- Incidents that are **inactive** (`active = false`).
7+
- Incidents that were closed **150 days ago or earlier**.
8+
The records are moved to the archive table `ar_incident`, which preserves all necessary fields for historical reference.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var gr = new GlideRecord('incident');
2+
gr.addQuery('state', 7); // Closed
3+
gr.addQuery('active', false);
4+
gr.addQuery('closed_at', '<=', gs.daysAgo(150));
5+
gr.query();
6+
while (gr.next()) {
7+
var ar = new GlideRecord('ar_incident'); //ar_incident is the new table for storing archive data
8+
ar.initialize();
9+
ar.short_description = gr.short_description;
10+
ar.description = gr.description;
11+
// Copy other necessary fields
12+
ar.insert();
13+
gr.deleteRecord(); // deleting from incident table if record in inserted in the archived table
14+
}

0 commit comments

Comments
 (0)