- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 03:15 AM
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
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 03:22 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 03:58 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 03:29 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader