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-20-2023 01:33 PM
If anyone out there has some ideas or experience they could share it would be greatly appreciated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2023 01:44 PM
Hi,
In the question it sounds like you have RITMs that are still open, but in the script you are attempting to close the parent Request, is that correct?
The requests in the query could have more than one RITM connected, and might not be ready to be closed?
Could you please clarify this, and I will attempt to help you with the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2023 09:26 AM
Hi Olan,
That would be amazing if you can assist. There is only the 1 RITM in every single request.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2023 11:51 PM
Okay, so can I assume that you want to close out ALL RITM that is for this particular Catalog item, since you have done a query with all active records of that item.
I would make some smaller changes to the script, and then do these steps;
1. Disable the email sending by adjusting the property to temporary not send any emails.
2. Run the script as provided below.
3. Go to the emails table, and change the emails generated from the script, so they wont be sent (either by deleting them, or by setting a property on them as sent)
4. Activate the email sending again, disabled in step 1.
The reason for not running/using .setWorkflow(false) is because it disables ALL business rules that should run when the RITMs is closed, it does not only disable the email sending.
var ritmQuery = "active=true^cat_item=770f9db81beab81038a57732dd4bcbfa";
var reqItem = new GlideRecord("sc_req_item");
reqItem.addEncodedQuery(reqQuery);
reqItem.setLimit(1); // remove/comment out this line after you have evaluated that the script changes were correct
reqItem.query();
while(reqItem.next()) {
reqItem.setValue('active', false);
reqItem.setValue('stage', 'complete');
reqItem.setValue('state'. '3'); // closed complete
reqItem.autoSysFields(false); // used if you dont want to change the last updated date/last updated by
reqItem.update();
}