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..ef8a14f1fe --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Archive Request/Archive scriptinclude.JS @@ -0,0 +1,27 @@ +(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.addQuery('state', 'IN', 'closed_complete,closed_incomplete'); + 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(); + } +})(); 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.