will closing bulk sctask with workflow false still trigger notification of RITM and REQ on autoclose

saint
Tera Expert

How to bulk close sc_task records without triggering closure emails on RITM (sc_req_item) and REQ (sc_request)

10 REPLIES 10

Tanushree Maiti
Mega Patron

Hi @saint 

 

Use setWorkflow(false) is the recommended method to prevent notifications.

Refer: KB0858407 Email notifications not being fired due to setWorkflow(false) or setUseEngines(false) 

 

You must use  use a Fix Script (preferred) or a Background Script to bulk close ServiceNow Catalog Tasks  without triggering closure emails on related (RITM) and (REQ) records 

 

Sample Script (Not tested): 

var targetState = 3; // 3 = Closed Complete, 4 = Closed Incomplete, 7 = Closed Skipped
var batchSize = 200; // update it as per your requirement
var encodedQuery = 'active=true^stateNOT IN3,4,7';

var gr = new GlideRecord('sc_task');
gr.addEncodedQuery(encodedQuery);
gr.setLimit(5000);
gr.query();
var count = 0;
while (gr.next()) {
gr.setWorkflow(false);
gr.active = false;
gr.state = targetState;
gr.comments = "Bulk closed by administrator without email.";
gr.update();
count++;
if (count % batchSize == 0) {
gs.print(count + " tasks closed...");
}
}
gs.print('Total Tasks Closed: ' + count);

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Hi @Tanushree Maiti , Thank you for your response.

 

I’m able to auto-close the SCTasks, but when they close, it rolls up and automatically closes the associated RITM and the related REQ. The REQ closure is triggering an email, which I want to avoid.
I don’t want to set or modify any values on the related RITM or REQ through the script. I only want to prevent the email notification on closure. So I’m trying to use setWorkflow(false) on the related RITM and REQ to stop the email trigger. 

Hi @saint ,

 

Logically if fulfillment is done ( sc_task activity)  (here forced one) , corresponding RITM ( if it is not associated with any open other sc_task) and REQ ( if it is not attached with other RITM ) should be closed.

 

Add setUseEngines(false)  just next line of SerWorkflow(false) and try.

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Hi @Tanushree Maiti I've tried using setUseEngines(false) as mentioned but the REQ email still triggers.