From 371373ff60bcdeb06f6a3cdb4fc90a5e68f43c91 Mon Sep 17 00:00:00 2001 From: Maheshkh9738 Date: Wed, 29 Oct 2025 23:28:41 +0530 Subject: [PATCH 1/3] Create Readme.md --- .../Catalog Client Script/Archive Request/Readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 Client-Side Components/Catalog Client Script/Archive Request/Readme.md diff --git a/Client-Side Components/Catalog Client Script/Archive Request/Readme.md b/Client-Side Components/Catalog Client Script/Archive Request/Readme.md new file mode 100644 index 0000000000..9abc91e78a --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Archive Request/Readme.md @@ -0,0 +1 @@ +This project introduces an automated process to archive old Service Catalog requests after a defined period (e.g., 90 days). It helps keep the request tables clean, improves performance, and ensures compliance with data retention policies. From ac5c0857c39331d53f2596e1a675ed012331e2fe Mon Sep 17 00:00:00 2001 From: Maheshkh9738 Date: Wed, 29 Oct 2025 23:29:25 +0530 Subject: [PATCH 2/3] Create Archive scriptinclude.JS --- .../Archive Request/Archive scriptinclude.JS | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Client-Side Components/Catalog Client Script/Archive Request/Archive scriptinclude.JS diff --git a/Client-Side Components/Catalog Client Script/Archive Request/Archive scriptinclude.JS b/Client-Side Components/Catalog Client Script/Archive Request/Archive scriptinclude.JS new file mode 100644 index 0000000000..cae2e4befb --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Archive Request/Archive scriptinclude.JS @@ -0,0 +1,26 @@ +(function executeArchive() { + var retentionDays = 90; // Change as needed + var cutoffDate = new GlideDateTime(); + cutoffDate.addDaysUTC(-retentionDays); + + var gr = new GlideRecord('sc_request'); + gr.addQuery('sys_created_on', '<=', cutoffDate); + gr.addQuery('active', false); // Only archive closed requests + gr.query(); + + while (gr.next()) { + // Optional: Copy data to archive table + var archive = new GlideRecord('x_your_scope_archived_requests'); + archive.initialize(); + archive.original_request = gr.number.toString(); + archive.archived_date = new GlideDateTime(); + archive.requester = gr.requested_for.toString(); + archive.status = gr.state.toString(); + archive.data_json = JSON.stringify(gr); + archive.insert(); + + // Mark original request as archived + gr.u_archived = true; // Add custom field + gr.update(); + } +})(); From 37b9204bc59ca1e4db709503fd3e5c9564f44936 Mon Sep 17 00:00:00 2001 From: Maheshkh9738 Date: Wed, 29 Oct 2025 23:35:09 +0530 Subject: [PATCH 3/3] Update Archive scriptinclude.JS --- .../Archive Request/Archive scriptinclude.JS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Client-Side Components/Catalog Client Script/Archive Request/Archive scriptinclude.JS b/Client-Side Components/Catalog Client Script/Archive Request/Archive scriptinclude.JS index cae2e4befb..ef8a14f1fe 100644 --- a/Client-Side Components/Catalog Client Script/Archive Request/Archive scriptinclude.JS +++ b/Client-Side Components/Catalog Client Script/Archive Request/Archive scriptinclude.JS @@ -5,7 +5,8 @@ var gr = new GlideRecord('sc_request'); gr.addQuery('sys_created_on', '<=', cutoffDate); - gr.addQuery('active', false); // Only archive closed requests + //gr.addQuery('active', false); // Only archive closed requests + gr.addQuery('state', 'IN', 'closed_complete,closed_incomplete'); gr.query(); while (gr.next()) {