Background Script to Delete Multiple Incident Records

Scott Shewan
Kilo Contributor

Hi All,

 

Long time reader, first time poster.

 

Due to legal requirements, one of our clients has requested that 5,000+ incident records are deleted. We have been provided with a .csv file that contains all of these incident numbers.

 

We need to create a background script that will delete these records, or failing that, update the resolution notes (or anywhere, really) with something unique so that we can report against this "something unique" and cmd-click through all of them and delete them that way.

 

Truth be told, I'm agnostic as to how we get this done short of deleting them one by one by one by one.

 

Any help would be appreciated. 

 

Thanks,
Scott

1 ACCEPTED SOLUTION

You don't have to add incident numbers in the script, You just need to include those in the Value field of your System property. In the image it was shown in Choices field which is Incorrect and you can clear them off. And then add its name in the script.

find_real_file.png

var incs = gs.getProperty('inc.numbers'); //Your property name here
var gr = new GlideRecord('incident');
gr.addEncodedQuery('numberIN'+incs);
gr.deleteMultiple();

View solution in original post

12 REPLIES 12

The type should be string, Here you go

find_real_file.png

i have a question here what if i have to delete the records ignoring the result of the encoded query(i.e the records returned from the encoded query must be there rest all should be deleted )

Scott Shewan
Kilo Contributor

Last question (I hope!):

 

In the script provided, where would I enter the incident numbers?

var incs = gs.getProperty('inc.numbers'); //Your property name here
var gr = new GlideRecord('incident');
gr.addEncodedQuery('numberIN'+incs);
gr.deleteMultiple();

 

Again, I'm sorry if this is obvious - I've been thrust into a Admin/Dev role but am still playing catch-up.

 

Thanks!

 

 

 

Number will go in system property

I have added a image in my last reply. You need to navigate to System properties table ie

sys_properties.LIST and add a new entry in here exactly as I have added in the image.

You could also reuse this in future if required.