From 3206d0aa0653da48c793aea76ac5c8a1ba5ab571 Mon Sep 17 00:00:00 2001 From: Code with bhav <92107107+bhavyaa30@users.noreply.github.com> Date: Thu, 9 Oct 2025 12:18:40 +0530 Subject: [PATCH 1/2] script.js --- .../script.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Core ServiceNow APIs/GlideRecord/Archiving Old Incident Records to Improve Performance/script.js diff --git a/Core ServiceNow APIs/GlideRecord/Archiving Old Incident Records to Improve Performance/script.js b/Core ServiceNow APIs/GlideRecord/Archiving Old Incident Records to Improve Performance/script.js new file mode 100644 index 0000000000..f75c926f73 --- /dev/null +++ b/Core ServiceNow APIs/GlideRecord/Archiving Old Incident Records to Improve Performance/script.js @@ -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 +} From e5753d7ba8490876fe71cb30daf9b8bff4d45d18 Mon Sep 17 00:00:00 2001 From: Code with bhav <92107107+bhavyaa30@users.noreply.github.com> Date: Thu, 9 Oct 2025 12:20:04 +0530 Subject: [PATCH 2/2] readme.md --- .../readme.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Core ServiceNow APIs/GlideRecord/Archiving Old Incident Records to Improve Performance/readme.md diff --git a/Core ServiceNow APIs/GlideRecord/Archiving Old Incident Records to Improve Performance/readme.md b/Core ServiceNow APIs/GlideRecord/Archiving Old Incident Records to Improve Performance/readme.md new file mode 100644 index 0000000000..6fe761fa84 --- /dev/null +++ b/Core ServiceNow APIs/GlideRecord/Archiving Old Incident Records to Improve Performance/readme.md @@ -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.