- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
How to bulk close sc_task records without triggering closure emails on RITM (sc_req_item) and REQ (sc_request)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @saint
Then go for workaround.
Identify which notification is getting trigger.
When you raise change to do this activity in prod in business off hour,
Update instruction as
1. deactivate notification A, Notification B etc.
2. Run fix script -> completed
3. Activate notification A, Notification B etc.
Or else
Raise a case (Hi ticket) to know why Notification triggering is not getting stop even after using setUseEngines(false) AND SerWorkflow(false).
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
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);
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
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.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Tanushree Maiti I've tried using setUseEngines(false) as mentioned but the REQ email still triggers.