Bulk Incident Closure with SLA Stopped/Inactive

upendrakumar
Tera Contributor

Hi All,

I want to close around 2000 incidents with below criteria by using the background script

1) No notification sent to user.

2) SLA should be stopped can somone help me with the background script.

3) Closure Notes should be added.

2 REPLIES 2

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @upendrakumar 

 

1) No notification sent to user.

Atul:  The only option is to disable closure email notifications temporarily while running the script to close incidents.

 

2) SLA should be stopped can somone help me with the background script.

Atul: As soon as you close the Incident, the SLA conditions will match, causing the SLA to stop. Alternatively, you can repair the SLA afterward if needed.

3) Closure Notes should be added.

Atul: Yes, you can add these in script.

 

https://www.servicenow.com/community/itsm-forum/background-script-to-close-all-incidents/td-p/917334

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0962238

 

https://www.servicenow.com/community/developer-forum/close-all-incidents-more-than-a-year-old/m-p/13...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

yuvarajkate
Giga Guru

1. No Notification Sent to User

To ensure no notifications are sent to users during the bulk update, we use the setWorkflow(false) method. This temporarily disables any associated workflows, which include notifications, during the update process. Once the script finishes processing, workflows for other records remain unaffected.

 

gr.setWorkflow(false);

 

 

2. SLA Should Be Stopped

SLAs (Service Level Agreements) track time-based progress on tasks, such as incidents. To stop SLAs for the incidents being closed, we:

  1. Query the task_sla table to find all SLAs associated with the incident (task field matches the sys_id of the incident).
  2. Update the stage field of the SLA record to paused, which effectively stops the SLA.

 

 

 

var slaGR = new GlideRecord('task_sla');
slaGR.addQuery('task', gr.sys_id);
slaGR.query();
while (slaGR.next()) {
    slaGR.setValue('stage', 'paused'); // Stop SLA
    slaGR.update();
}

 

This ensures that no SLAs remain active for the closed incidents.

 

3. Closure Notes Should Be Added

Closure notes are added to record the reason for the bulk closure of incidents, which helps maintain transparency and proper documentation. The script updates the close_notes and comments fields for each incident:

  • close_notes: Used to provide a specific reason for the closure.
  • comments: Captures additional notes that may be visible in the incident's activity log.

 

gr.setValue('close_notes', 'Closed in bulk operation with SLA stopped');
gr.comments = "Incident closed as part of bulk update";