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

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.

used above script and it worked.

just one query the above line where you are making wf false will it also affect the business rules as well.

 

thanks for the help

yes, it will stop triggering any BRs or workflows associated to those updated records.

Do be aware that this will perform pretty poor when it concerns a lot of records.

Consider using .updateMultiple instead.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn