Skip to content

Instantly share code, notes, and snippets.

@cmcdevitt
Created July 9, 2015 12:22
Show Gist options
  • Select an option

  • Save cmcdevitt/35855098c5eea8d63c3e to your computer and use it in GitHub Desktop.

Select an option

Save cmcdevitt/35855098c5eea8d63c3e to your computer and use it in GitHub Desktop.
Remove Demo CI Data. The following script identifies the impacted CIs, checking to ensure they are not relied on by any tasks.
// remove demo data CIs
var recCI = new GlideRecord('cmdb_ci')
recCI.addEncodedQuery("sys_created_on<javascript:gs.dateGenerate('2013-09-01','00:00:00')^sys_class_name!=cmdb_ci_snc_component^ORsys_class_name=NULL")
recCI.orderByDesc('sys_created_on')
recCI.query()
var logmsg = "Log Output\nRecords Found: " + recCI.getRowCount() + "\n";
while(recCI.next()){
var taskCI = new GlideRecord('task_ci');
taskCI.addQuery('ci_item', recCI);
taskCI.query()
if (taskCI.getRowCount() == 0) {
logmsg += "\t" + recCI.sys_id + "(" + recCI.sys_created_on + ") - " + recCI.sys_created_by + " - " + recCI.name + "\n";
recCI.delete()
};
}
gs.log(logmsg)
// Script Ends Here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment