
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2017 09:36 PM
Hi Guys,
I am trying to mass close 70,000ish Incident records.
There are mandatory fields that need to be completed otherwise the SLA Clock will keep running.
My Mandatory fields are: u_cause_code, u_resolution_code, u_cause_ci, u_solution, u_business_impact, u_cause_summary & u_incident_outage.
Cause code and resolution code are choice fields, cause CI field is a reference and business impact, resolution summary are free text.
Incident outage is a yes/no choice.
Each incident is identified by the same "assigned to" support group and generated "short description".
I am assuming this will be done via a clean-up script, my knowledge on scripting this type of thing is little to none.
Any assistance on this or aducation will be greatly appreciated.
Thank you,
Phil.
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2017 07:35 PM
Hi Philip,
Either you can run a background script to do the same which is already provided by Aanchal or you can create buisness rule .
This article might be helpful for you :
http://wiki.servicenow.com/index.php?title=Closing_Multiple_Incidents#gsc.tab=0
The conditions can be modified according to your requirements.
Also you might want to write a Background Script to close the incidents required from back end and setting the workflow as well as to false so that no Notifications gets triggered while closing the Incidents as per the script mentioned below:
Script:
var gr = new GlideRecord('incident');
var string='active=true^state=2'; //Replace your Query here
gr.addEncodedQuery(string)
gr.query();
while(gr.next())
{
gr.setWorkflow(false); //This would not allow any Notifications to get trigger while closing
gr.autoSysFields(false);
gr.state = 10; //Replace your Closed State value here
gr.update();
}
In the code shared above you can get your Query required by simply Navigating to the list view of incidents and filter the Records which you want to close and then Run the filter. Post Run Right click on the query and copy the same as shown below:
Hope this helps.Mark the answer as correct/helpful based on impact.
Thanks,
Aditya Telidevara
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2017 10:06 PM
Thanks Vab, I wasn't aware about this function. DO you know in which release this was added?
HI Philip
Please use the script from Vab and be careful while using this. See the attahced notes.
When changing field values, use setValue() instead of directly setting the field (field = something). When using updateMultiple(), directly setting the field (gr. state = 4) results in all records in the table being updated instead of just the records returned by the query.
-Harsh
When changing field values, use setValue() instead of directly setting the field (field = something). When using updateMultiple(), directly setting the field (gr. state = 4) results in all records in the table being updated instead of just the records returned by the query.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2018 11:24 PM
So i have only just gotten back to this and i really appreciate both of your assistance on this.
ok so, i have:
var inc_query =("assignment_group=832f75134fd12ac0657b30b01310c7e4^opened_atONLast month@javascript:gs.beginningOfLastMonth()@javascript:gs.endOfLastMonth"());
// setup a query here to find the required incident to update
var gr = new GlideRecord('incident');
gr.addEncodedQuery(inc_query);
gr.query();
while(gr.next()){
gr. state = 4
gr.setValue("u_cause_code","Cancelled");
gr.setValue("u_resolution_code","Closed");
gr.setValue("u_cause_ci","100b05f1dc4445408d1a9a863edee55a");
gr.setValue("u_business_impact","NONE");
gr.setValue("u_cause_summary","NO CAUSE");
gr.setValue("u_solution","CANCELLED");
gr.setValue("u_incident_outage","No");
gr.updateMultiple();
}
but i am getting:
Evaluator: org.mozilla.javascript.EcmaError: assignment_group=832f75134fd12ac0657b30b01310c7e4^opened_atONLast month@javascript:gs.beginningOfLastMonth()@javascript:gs.endOfLastMonth is not a function. Caused by error in script at line 1 ==> 1: var inc_query = ("assignment_group=832f75134fd12ac0657b30b01310c7e4^opened_atONLast month@javascript:gs.beginningOfLastMonth()@javascript:gs.endOfLastMonth"()); 2: // setup a query here to find the required incident to update 3: 4: var gr = new GlideRecord('incident');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2017 11:30 PM
Hi Philip,
run below query.
open incident table and filter all the incidents which you wanted to deleted,
right click on the filter and do copy query.
var gr = new GlideRecord();
gr.addEncodedQuery("copied query");
gr.setValue('mandatoryField1', 'text1');
gr.setValue('mandatoryField1', 'text2');
gr.updateMultiple();
Note: You can also close without filling mandatory fields as background script will run on top of business rules.
Thanks,
Sireesha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2017 07:35 PM
Hi Philip,
Either you can run a background script to do the same which is already provided by Aanchal or you can create buisness rule .
This article might be helpful for you :
http://wiki.servicenow.com/index.php?title=Closing_Multiple_Incidents#gsc.tab=0
The conditions can be modified according to your requirements.
Also you might want to write a Background Script to close the incidents required from back end and setting the workflow as well as to false so that no Notifications gets triggered while closing the Incidents as per the script mentioned below:
Script:
var gr = new GlideRecord('incident');
var string='active=true^state=2'; //Replace your Query here
gr.addEncodedQuery(string)
gr.query();
while(gr.next())
{
gr.setWorkflow(false); //This would not allow any Notifications to get trigger while closing
gr.autoSysFields(false);
gr.state = 10; //Replace your Closed State value here
gr.update();
}
In the code shared above you can get your Query required by simply Navigating to the list view of incidents and filter the Records which you want to close and then Run the filter. Post Run Right click on the query and copy the same as shown below:
Hope this helps.Mark the answer as correct/helpful based on impact.
Thanks,
Aditya Telidevara

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 05:53 PM
This is my final script which works fantastic!
Thanks for everyones help.
var gr = new GlideRecord('incident');
gr.addEncodedQuery('assignment_group=832f75134fd12ac0657b30b01310c7e4^opened_atONLast month@javascript:gs.beginningOfLastMonth()@javascript:gs.endOfLastMonth()');
gr.query();
while(gr.next()){
gr.setValue('state','7'); // 'closed' status.
gr.setDisplayValue('u_cause_code','Cancelled');
gr.setDisplayValue('u_resolution_code','N/A');
gr.setDisplayValue('u_cause_ci','100b05f1dc4445408d1a9a863edee55a'); // 'N/A'
gr.setValue('u_business_impact','NONE');
gr.setValue('u_cause_summary','NO CAUSE');
gr.setValue('u_solution','CANCELLED');
gr.setDisplayValue('u_incident_outage','No');
gr.setDisplayValue('u_requestor','Corporate Systems');
gr.update();
}