Bulk delete incidents from incident table based on "short description" value and "state"

Elias9
Kilo Contributor

Hi I am  new to service now and trying to bulk delete unwanted incidents from incident table based on short description value "AP disconnected" and state of incident is "New"

Instead of selecting and deleting each incident, how can I achieve this in one hit. If a script required to do this , can some help please.????

and what kind of script should i be using.???? and how to run it ? please bear with me I inherited this service now environment recently and I am new to this.

thank you folks

1 ACCEPTED SOLUTION

Anil Lande
Kilo Patron

Hi,

You can use background script or Fix Script to run server side scripts on demand.

find_real_file.png

1. Create a Fix script record and write below script:

find_real_file.png

 

And run the script to delete incidents.

I would suggest to use setLimit and delete 100/1000 incidents at a time.

 

deleteIncidents();

function deleteIncidents() {

    var incGr = new GlideRecord('incident');
	incGr.addQuery('short_description','AP disconnected'); // 
	incGr.addQuery('state',1);   // state is New (check state value in your instance and replace)
    incGr.setLimit('100');
    incGr.setWorkflow(false);

    incGr.deleteMultiple();
}

 

Thanks,
Anil Lande 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

8 REPLIES 8

Anil Lande
Kilo Patron

Hi,

You can use background script or Fix Script to run server side scripts on demand.

find_real_file.png

1. Create a Fix script record and write below script:

find_real_file.png

 

And run the script to delete incidents.

I would suggest to use setLimit and delete 100/1000 incidents at a time.

 

deleteIncidents();

function deleteIncidents() {

    var incGr = new GlideRecord('incident');
	incGr.addQuery('short_description','AP disconnected'); // 
	incGr.addQuery('state',1);   // state is New (check state value in your instance and replace)
    incGr.setLimit('100');
    incGr.setWorkflow(false);

    incGr.deleteMultiple();
}

 

Thanks,
Anil Lande 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Thank you very much Anil for your swift response. You are a legend I appreciate it. you saved heaps of time.

Just a question, is the state value translated to a number ? for example 

 new = 1, 

in progress = 2,

on hold = 3 ?   and so on ? and if so how would i find these numbers for each state value?

 

 

Regards

Elias

 

 

my other question is, using fix script can you run it on demand or it runs always?

It is on Demand script, you have to run it manually.

We prefer Fix script because you can capture it in Update set and move to next instance after testing it on non-prod instances.

 

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande