Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

background script to close all incidents.

akshayjain
Tera Expert

What should I write in background script to close all incidents or delete all incidents

6 REPLIES 6

ARG645
Tera Guru
closeStaleIncidents();
function closeStaleIncidents() {
    var closeState = 7;
    var gr = new GlideRecord('incident');
    gr.query(); 
    gr.setValue('state', closeState);
    gr.updateMultiple();
    //Use gr.deleteMultiple(); to delete all Incidents
}

Reference: 

Pro Tip: Use updateMultiple() for Maximum Efficiency! by Tim Woodruff

sachin_namjoshi
Mega Patron

Hi Akshay,

 

Please mark my answer as correct so that others can benefit from similar question.

 

Regards,

Sachin