close multiple incidents without sending email notifications

Nikita35
Kilo Guru

hello 

 

I would like to know how can we achieve this in the best possible way.

Knowing that via backround script but according to my understanding Will it not affect system performance?

 

Any thoughts are welcome.

 

Regards,

Nikita Khavnekar

2 REPLIES 2

darius_koohmare
ServiceNow Employee
ServiceNow Employee

You could do a background script, but write the logic so that you batch a few records. Also add in sleep(); calls to improve performance, as I'm sure it's not extremely time sensitive to bulk close items. Also, set setWorkflow(false) to prevent BR/notifications.

 

var gr = new GlideRecord('incident');  
gr.setLimit(100); //will update 100 records at a time
gr.addQuery('active', 'true');  
gr.query();  
while(gr.next())  
  {  
  gr.short_description = 'test';  
  gr.setWorkflow(false); //Will not fire BR/email notifications  
  gr.update();  
  }  

Also since the background script runs as the given user, you could also add logic to the email notification so that updated by != that user to ensure no emails trigger.