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:49 AM
I'd still recommend the built-in Table Cleaner. It relies on a scheduled job that runs every hour and deletes all records that match the conditions you configure for it. For example: all records wich were created over 12 months ago, and are closed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2016 08:53 AM
Agreed; this is probably the easiest method; the majority of the work is done for you, you just need to set criteria.
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2016 08:50 AM
Hi Leah,
It is possible to create a scheduled script execution that will run every month and clean your data. But are you really sure you want to delete this data? Once deleted you want be able to get it back anymore.
Here is a quick script that you can run from background scripts as admin to see all incidents created before last 12 months:
encodedQuery='sys_created_on<javascript:gs.monthsAgoStart(12)'
var gr = new GlideRecord('incident');
gr.addEncodedQuery(encodedQuery);
gr.query();
while(gr.next()){
gs.print(gr.number);
}
On my test instance running this I get:
[0:00:00.012] Script completed in scope global: script
*** Script: INC0000001
*** Script: INC0000002
*** Script: INC0000003
*** Script: INC0000004
*** Script: INC0000005
*** Script: INC0000007
Now if I would like to delete these records I would change script like:
encodedQuery='sys_created_on<javascript:gs.monthsAgoStart(12)'
var gr = new GlideRecord('incident');
gr.addEncodedQuery(encodedQuery);
gr.deleteMultiple();
To create a scheduled script execution:
System Definition -> Scheduled Jobs -> New -> Automatically run a script of your choosing
Run -> Monthly
Run this script: second script I pasted above
Same script can be used for other tables just by changing the tablename.
Before proceeding with this, be sure you check again all the exact requirements. Testing should be done first on a subproduction instance before deploying anything in production.
Hope this helps.
Regards,
Sergiu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2016 06:30 AM
So if I wanted to delete incidents/problems/changes that had closed >12 months ago, how would the script be adjusted?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2016 06:48 AM
This script should do it:
encodedQuery='closed_at<javascript:gs.monthsAgoStart(12)'
var gr = new GlideRecord('incident');
gr.addEncodedQuery(encodedQuery);
gr.deleteMultiple();
var gr = new GlideRecord('problem');
gr.addEncodedQuery(encodedQuery);
gr.deleteMultiple();
var gr = new GlideRecord('change_request');
gr.addEncodedQuery(encodedQuery);
gr.deleteMultiple();
In my case, out of box, we are using field called "closed_at" for time when incident/change/problem are closed. If it's a different field in your case, you need to adapt the script.
As mentioned before, test this on subproduction first (using a clone from production would make the test even more appropriate to production case).
Regards,
Sergiu