How can I delete tickets >12 months old?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2016 08:08 AM
Have a requirement to delete incidents, problems, and changes >12 months old and I don't know how to do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2016 08:47 AM
Please create a scheduled script execution, to get more info refer the below link -
Creating a Scheduled Job - ServiceNow Wiki
In the script section, please write the script as below - I would like Tim to review
var enq = "sys_updated_onRELATIVELT@month@ago@12";
var grInc = new GlideRecord('incident');
grInc.addEncodedQuery(enq);
grInc.query();
grInc.deleteMultiple();
var grChg = new GlideRecord('change_request');
grChg.addEncodedQuery(enq);
grChg.query();
grChg.deleteMultiple();
var grPrb = new GlideRecord('problem');
grPrb.addEncodedQuery(enq);
grPrb.query();
grPrb.deleteMultiple();
You can schedule this script to run every month regularly and this will automatically delete the 12 months old records.
Make sure that you are sure about deletion, because this wiil remove the records. Its preferred to make a "soft" delete, that is making Active field as False
and wait for one more month and then delete.
But its your decision, the above script will do the trick.
Mark if it is helpful or correct, feedback is appreciated

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2016 08:52 AM
I agree, encoded query is the better route.
Cheers,
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2016 08:52 AM
The query() call is not really needed when you want to delete data. You can just call directly deleteMultiple().
I also think customer refers to data created before last 12 months, not updated.
Regards,
Sergiu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2018 01:28 AM
For a straight-up deletion, use the out-of-box Table Cleaner functionality and add a line to the Auto Flushes [sys_auto_flush] table.