diff --git a/Scheduled Jobs/Schedule Job For Data Clean Up/readme.md b/Scheduled Jobs/Schedule Job For Data Clean Up/readme.md new file mode 100644 index 0000000000..808f1a6cf0 --- /dev/null +++ b/Scheduled Jobs/Schedule Job For Data Clean Up/readme.md @@ -0,0 +1,28 @@ +**Overview :** + This script automates the cleanup of old closed incidents in the ServiceNow instance. It helps maintain a clean and efficient database by removing records that are no longer needed, thereby improving system performance and manageability. + + +**Features** + + **Automatic Cleanup**: Deletes closed incidents that are older than 90 days. + + **Customizable Timeframe**: Easily adjustable parameters to change the age of incidents for cleanup. + + **Logging:** Outputs the number of incidents deleted to the system logs for tracking purposes. + + +**Prerequisites** + Access to a ServiceNow instance with appropriate permissions to run scripts. + Knowledge of how to create Scheduled Jobs in ServiceNow. + + +**Installation** + **Create a New Scheduled Job:** + Navigate to System Definition > Scheduled Jobs in your ServiceNow instance. + Click on New to create a new Scheduled Job. + + +**Configure the Job:** + **Name**: Enter a descriptive name for the job, e.g., "Cleanup Old Closed Incidents." + **Run**: Set the desired schedule for when you want the job to run (e.g., daily, weekly). + **Script**: Copy and paste the provided javascript into the script section of the Scheduled Job. diff --git a/Scheduled Jobs/Schedule Job For Data Clean Up/scheduleJob_for_DataCleanup.js b/Scheduled Jobs/Schedule Job For Data Clean Up/scheduleJob_for_DataCleanup.js new file mode 100644 index 0000000000..bc29604d30 --- /dev/null +++ b/Scheduled Jobs/Schedule Job For Data Clean Up/scheduleJob_for_DataCleanup.js @@ -0,0 +1,5 @@ +var gr = new GlideRecord('incident'); +gr.addQuery('sys_created_on', '<=', gs.daysAgo(90)); +gr.addQuery('state', 'Closed'); +gr.deleteMultiple(); +gs.info('Deleted old closed incidents older than 90 days.');