how to bulk close incidents

srinivasd
Kilo Explorer

how to bulk close incidents

6 REPLIES 6

shloke04
Kilo Patron

Hi,



Best Option would be to write a Background Script to close the incidents required from back end and setting the workflow as well as to false so that no Notifications gets triggered while closing the Incidents as per the script mentioned below:



Script:



var gr = new GlideRecord('incident');


var string='active=true^state=2';                                 //Replace your Query here


gr.addEncodedQuery(string)


gr.query();


while(gr.next())


{


gr.setWorkflow(false);                                                               //This would not allow any Notifications to get trigger while closing


gr.autoSysFields(false);


gr.state = 10;                                                                                               //Replace your Closed State value here


gr.update();


}



find_real_file.png



In the code shared above you can get your Query required by simply Navigating to the list view of incidents and filter the Records which you want to close and then Run the filter. Post Run Right click on the query and copy the same as shown below:



find_real_file.png



Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

One thing to remember if you are playing with state on incident.


Always keep the incident state and state in sync. So if you are going to use "gr.setWorkflow(false)" (which is good to use if you updating records in multiple )


then manually set incident state in the script as well. So your final script will be :



var gr = new GlideRecord('incident');


var string='active=true^state=2';                                 //Replace your Query here


gr.addEncodedQuery(string)


gr.query();


while(gr.next())


{


gr.setWorkflow(false);                                                               //This would not allow any Notifications to get trigger while closing


gr.autoSysFields(false);


gr.state = 4;    


gr.incident_state = 4                                                                                       //Replace your Closed State value here


gr.update();


}