- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2018 07:36 AM
Hi All,
Our incident table is used by two Help-desks (IT & Finance) We separate the records using an "Incident Type" field.
There is a requirement to not carry the Finance records through to our non-prod instances when we clone. At present we have around 100K Finance records. Would you suggest creating a clone cleanup script to delete these records using the script below?
var gr = new GlideAggregate('incident');
gr.addQuery('u_incident_type','Finance');
gr.query();
while (gr.next()){
gr.deleteMultiple();
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2018 09:09 AM
Cleanup script is the only way, since incident is extended from task table, and the exclude tables & data preservers (if the backup fails) won't work on extended tables, they only work on parent tables.
As for not using the while loop, the system takes your GlideRecord and does the looping in the back-end, so you don't have to. There is one large downside (for me) of deleteMultiple() is that it does not delete the attachments, so I don't usually only use deleteRecord(), while using a while loop (similar to what your initial example.
var gr = new GlideRecord('incident');
gr.addQuery('u_incident_type','Finance');
gr.query();
while (gr.next()){
gr.deleteRecord();
}
I had to do this for the ServiceNow Security Incident scoped app, since our Security Team preferred to create fake data for us if we needed it in Sub-Production environments. I also had to some some extra work do allow me to delete the records in the scoped app by the way.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2018 07:44 AM
Close, this is what I would use the following instead.
var gr = new GlideRecord('incident');
gr.addQuery('u_incident_type','Finance');
gr.query();
gr.deleteMultiple();
Thanks,
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2018 08:26 AM
Thanks,
Just wondering if cleanup script is the best way, not sure how long it would take to delete the records after each clone.
Can you also explain why we would not put the delete within a while loop?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2018 09:09 AM
Cleanup script is the only way, since incident is extended from task table, and the exclude tables & data preservers (if the backup fails) won't work on extended tables, they only work on parent tables.
As for not using the while loop, the system takes your GlideRecord and does the looping in the back-end, so you don't have to. There is one large downside (for me) of deleteMultiple() is that it does not delete the attachments, so I don't usually only use deleteRecord(), while using a while loop (similar to what your initial example.
var gr = new GlideRecord('incident');
gr.addQuery('u_incident_type','Finance');
gr.query();
while (gr.next()){
gr.deleteRecord();
}
I had to do this for the ServiceNow Security Incident scoped app, since our Security Team preferred to create fake data for us if we needed it in Sub-Production environments. I also had to some some extra work do allow me to delete the records in the scoped app by the way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2018 09:29 AM
Thanks for taking the time to explain.
I did test excluding the sys_attachment table during a test clone today and it broke the instance interface as all the images were missing 🙂