- 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
07-05-2018 08:10 AM
I did also look at scrambling the data using clone scripts but its proving pretty tricky as you need to think about the following.
* On any record where there is a free text field, replace the data with someone else.
* Delete the sys_journal entry's for each record to remove comments/work notes.
* Delete sys_sudit entry's for each record and then disable auditing on each table to not let it show the previous values in the history tab.
Any guidance would be helpful? maybe i am overthinking it and there is an easier way?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 06:32 PM
So the cleanup script wasn't sufficient, was it because of the reasons you have listed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2018 01:15 AM
I have the following script that i have put together. At present i have hardcoded it to one incident for testing purposes, which sort of does the jobs.
gs.log('Starting updateText');
var rec = new GlideRecord('incident');
rec.addQuery('number','INC06808982');
rec.query();
while(rec.next()) {
rec.setWorkflow(false); // Do not run any other business rules.
rec.description = 'Dummy Text Here';
rec.short_description = 'Dummy Text Here';
rec.close_notes = 'Dummy Text Here';
rec.update();
gs.log('Completed updateText');
}
gs.log('Starting deleteJournal');
var sjf = new GlideRecord('sys_journal_field');
sjf.addQuery('element_id', 'd554fa900f879340d07ff68ce1050eda');
sjf.query();
while(sjf.next()) {
sjf.deleteRecord();
}
gs.log('Completed deleteJournal');
gs.log('Starting deleteEmails');
var se = new GlideRecord('sys_email');
se.addQuery('instance', 'd554fa900f879340d07ff68ce1050eda');
se.query();
while(se.next()) {
se.deleteRecord();
}
gs.log('Completed deleteEmails');
gs.log('Starting deleteAudit');
var sa = new GlideRecord('sys_audit');
sa.addQuery('documentkey', 'd554fa900f879340d07ff68ce1050eda');
sa.query();
while(sa.next()) {
sa.deleteRecord();
}
gs.log('Completed deleteAudit');
gs.log('Starting deleteHistory');
var shs = new GlideRecord('sys_history_set');
shs.addQuery('id', 'd554fa900f879340d07ff68ce1050eda');
shs.query();
while(shs.next()) {
shs.deleteRecord();
}
gs.log('Completed deleteHistory');