Bulk changes to Incident tickets

Mark several incident tickets as spam

 

Warning, Resolving an Incident will NOT PREVENT the SLA breach notifications from sending. To fully stop an SLA Breach, the Incidents must be set to state Closed, which is '7'. If you run the script below, and then run the next script to set closed, that is sufficient to fully stop SLA breech notifications before they happen. Alternatively, we could fully delete the Incidents, which would trivially stop the SLA breech notifications.

//var incidents = ["INC0333439"];
//var caller = 'somit@yale.edu';
// sys_id for somit@yale.edu
var u_sys_id = '6bb31c742bd62500fcb01abf59da1546';
var date = '2014-07-31';
var state = '6';
var inc_num = '';
// state 6 is resolved
 
    var gr = new GlideRecord('incident');
    gr.addQuery('caller_id',u_sys_id);
    gr.addQuery('opened_at','ON',date);
    gr.query();
 
    var counter=0;
    while (gr.next()) {
      inc_num = gr.number;
      gs.print(inc_num);
      update_one_inc(inc_num);
      counter++;
    }
    gs.print("counter is: " + counter);
    gs.print("inc_num is: " + inc_num);
 
// the portion above successfully found 1032 incidents!

function update_one_inc ( inc_num) {
 var gr2 = new GlideRecord('incident');
 gr2.addQuery('number',inc_num);
 gr2.query();
 if ( gr2.next() ) {
   gr2.incident_state = state;
   gr2.u_incident_type = 'Invalid';
   // incident type 5 is 'invalid'
   gr2.u_level_1 = 'Data';
   //gr2.u_it_provider_service = 'Other IT Provider Service';
   gr2.u_it_provider_service = '22bc2a165d7718007ac08a508e67e8fe';
   //gr2.u_it_business_service = 'Other IT Business Service';
   gr2.u_it_business_service = 'f3aaaad25d7718007ac08a508e67e875';
   gr2.description = 'Spam email';
   gr2.close_code = 'Invalid Incident';
   // close code 9 is 'invalid incident'
   gr2.close_notes = 'Spam email';
   gr2.autoSysFields(false);
   gr2.setForceUpdate(true);
   gr2.setWorkflow(false);
   gr2.update();
 }
}

Close a large batch of incidents

//var incidents = ["INC0333439"];
//var caller = 'somit@yale.edu';
// sys_id for somit@yale.edu
var u_sys_id = '6bb31c742bd62500fcb01abf59da1546';
var date = '2014-07-31';
var state = '7';
var inc_num = '';
// state 6 is closed
 
    var gr = new GlideRecord('incident');
    gr.addQuery('caller_id',u_sys_id);
    gr.addQuery('opened_at','ON',date);
    gr.query();
 
    var counter=0;
    while (gr.next()) {
      inc_num = gr.number;
      gs.print(inc_num);
      close_one_inc(inc_num);
      counter++;
    }
    gs.print("counter is: " + counter);
    gs.print("inc_num is: " + inc_num);
 
// the portion above successfully found 1032 incidents!
 
function close_one_inc ( inc_num) {
 var gr2 = new GlideRecord('incident');
 gr2.addQuery('number',inc_num);
 gr2.query();
 if ( gr2.next() ) {
   gr2.incident_state = state;
   gr2.update();
 }
}

 

Reopen closed incidents

var incidents = ["INC0145723","INC0145726","INC0145736","INC0145721","INC0145718","INC0145729","INC0145722","INC0145727","INC0145716","INC0145711"];
var state = '3';

for (i=0; i<incidents.length; i++) {
    var gr = new GlideRecord('incident');
    gr.addQuery('number',incidents[i]);
    gr.query();
    if(gr.next()) {
        gs.print("old state = " + gr.incident_state);
        gr.incident_state = state;
        gr.update();
    }
}