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

what about state value ? how to find the value of state

 

 

thank you again

 

There are multiple ways,

1. Filter records in list view to show New records and copy filter query:

find_real_file.png

 

Paste the query anywhere and see the state value.

2. Open dictionary of state field and see the state choices.

find_real_file.png

 

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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can find the state value by checking the choice list for state field on incident

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Elias9
Kilo Contributor

ok thank you heaps , tested in dev...worked...then deployed to production. 

thanks heaps for help