The Now Platform® Washington DC release is live. Watch now!
[asset|aid=344|format=Small|formatter=asset_lightbox|title=destructive_god.jpg|width=150|height=150|align=right]Wanton destruction is generally a bad thing (though fun to watch on a movie, if the special effects are good). Carefully controlled destruction can be a good thing — especially if you need to get rid of some records in a database table.
For example, suppose your company had a datacenter on the Deepwater Horizon drill rig that burned and sank earlier this year. Your people got off ok (unlike the unfortunate 11 who died in the accident), but your equipment burned, then sank under a mile of salt water. Now your boss wants you to get rid of all these computers (950 of them). You could go delete them one page at at time, but that would be very tedious. You'd like to write a script to do it, but how? If this question (or a similar one) has been keeping you awake at night, this post's for you!
Well, if you happen to know about the deleteRecord() method on GlideRecord, you might try something like this:
var gr = GlideRecord('cmdb_ci_computer');
gr.addQuery('location.name', 'Deepwater Horizon');
gr.query();
while (gr.next())
gr.deleteRecord();
var gr = GlideRecord('cmdb_ci_computer');
gr.addQuery('location.name', 'Deepwater Horizon');
gr.deleteMultiple();
var gr = GlideRecord('cmdb_ci');
gr.deleteMultiple();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.