Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Purpose
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.
## Solution Overview
Use **ServiceNow Archive Rules** to automatically move incidents to an archive table based on specific conditions:
- Incidents that are **closed**.
- Incidents that are **inactive** (`active = false`).
- Incidents that were closed **150 days ago or earlier**.
The records are moved to the archive table `ar_incident`, which preserves all necessary fields for historical reference.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var gr = new GlideRecord('incident');
gr.addQuery('state', 7); // Closed
gr.addQuery('active', false);
gr.addQuery('closed_at', '<=', gs.daysAgo(150));
gr.query();
while (gr.next()) {
var ar = new GlideRecord('ar_incident'); //ar_incident is the new table for storing archive data
ar.initialize();
ar.short_description = gr.short_description;
ar.description = gr.description;
// Copy other necessary fields
ar.insert();
gr.deleteRecord(); // deleting from incident table if record in inserted in the archived table
}
Loading