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.
Code Block |
---|
//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
Code Block |
---|
//var incidents = ["INC0145723","INC0145726","INC0145736","INC0145721","INC0145718","INC0145729","INC0145722","INC0145727","INC0145716","INC0145711"INC0333439"]; //var statecaller = '3somit@yale.edu'; // sys_id for (i=0; i<incidents.length; i++) {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('number'opened_at','ON',incidents[i]date); gr.query(); if var counter=0; while (gr.next()) { inc_num = gs.print("old state = " + gr.incident_stategr.number; gs.print(inc_num); close_one_inc(inc_num); gr.incident_state = statecounter++; } grgs.update(print("counter is: " + counter); } } |
Lou often gives us lists of change fields
Here's how to make them better with bash. This still needs some work, but is better than nothing:
Code Block |
---|
[db692@mas013-new ~]$ cat asdf CHG0006629 CHG0004449 # the next line is for gnu sed [db692@mas013-new ~]$ echo -n "var changes = [\""; cat asdf | sed ':a;N;$!ba;s/\n/","/g' var changes = ["CHG0006629","CHG0004449 # here's one for MAC (BSD) sed zuse:~ db692$ echo -n "var incidents = [\""; cat jkl | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/'\",\"'/g' 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
Code Block |
---|
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();
}
}
|