How to close multiple incidents in one go?

Servicenow10
Kilo Guru

hi,

I have a backlog of more than 1000 incidents which i want to close in one attempt which are pending from last 6 months.

how can i achieve it ?

 

thanks all 

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi,

You can write a fix script  which fetches the list of incidents that are open from last 6 months. You can change the filter as you need in the below code. 

var gr = new GlideRecord("incident");
gr.addEncodedQuery("stateNOT IN6,7,8^sys_created_on>=javascript:gs.beginningOfLast6Months()");
gr.query();
while(gr.next()) {
  gr.state=6; //closed state
  //put other fields if anythign to fill in (like mandatory ones during close)
  gr.setWorkflow(false);
  gr.update();
}

Mark the comment as a correct answer and helpful if this solves the problem.

View solution in original post

6 REPLIES 6

Hi Mark,

Thanks for pointing that out.

Dell, here is the updated script. Kindly test on dev before running on prod.

var gr = new GlideRecord("incident");
gr.addEncodedQuery("stateNOT IN6,7,8^sys_created_on>=javascript:gs.beginningOfLast6Months()");
gr.setValue('state', 6); //mention the closed state value
gr.setWorkflow(false);
gr.updateMultiple();

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

1) Form the encoded query from the table list

2) then use one time schedule job to update those incidents

Sample script below

1) Remember to set the state, incident_state and active field during closure

var gr = new GlideRecord("incident");
gr.addActiveQuery();
gr.addEncodedQuery("sys_created_on>=javascript:gs.beginningOfLast6Months()");
gr.query();
while(gr.next()) {
  gr.state = 7; //closed state
  gr.incident_state = 7; // closed
  gr.active = false;
  gr.work_notes = 'Closed by script';
  gr.setUseEngines(false); // to avoid data policy
  gr.setWorkflow(false); // to avoid triggering business rule
  gr.update();
}

Regards
Ankur

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