to close requests, their items and workflows without triggering emails
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2023 05:16 PM
Hello everyone,
I have 159 records spread across 2 items that were never closed out properly. They stretch back to 2021 and some have moved forward in approval, some not so many are at different work stages. At this point all of the work is done, but we need to clean this up. I want to close these out without triggering the workflow emails or the standard request notifications.
var reqQuery = "active=true^cat_item=770f9db81beab81038a57732dd4bcbfa";
var reqItem = new GlideRecord("sc_req_item");
reqItem.addEncodedQuery(reqQuery);
reqItem.query();
while(reqItem.next) {
var req = new GlideRecord("sc_request");
req.get(reqItem.request);
req.state = 3;
req.request_state = "closed_complete";
req.active = false;
req.setWorkflow(false); // prevent notifications from going out
req.update();
}
I have tried the code below but it just keeps running until it aborts. I am also unsure if this will do all I am hoping it will do. Has anyone else tried something similar?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2023 10:58 AM
Hi @chrisn_
Before closing requests you should close all the RITMs inside them
Try below code and see if it closes RITM records
var reqQuery = "active=true^cat_item=770f9db81beab81038a57732dd4bcbfa"; //query for RITMs to be closed
var reqItem = new GlideRecord("sc_req_item");
reqItem.addEncodedQuery(reqQuery);
reqItem.query();
while(reqItem.next) {
reqItem.state = 3; // Set the state to Closed Complete (change backend value if needed)
reqItem.setWorkflow(false); // prevent notifications from going out
reqItem.update();
}