Close RITM without generating remaining TASK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2024 07:31 AM
I am cleaning up our instance from years before I took over. There are a number of RITM opened from 2021 still. I would like to do a mass close out of these as they are no longer needed. However, if any of these have TASKs that still have not been generated, I do not want to flood the system with TASKs and confuse people. If I simply close the RITM, will any un-created TASKs open or will the RITM just close? What would be the preferred method for this be? Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2024 07:59 AM
Hi @Brent Cox ,
Please use the below script to close the RITM's without triggering any Br's or workflows in Scripts-Background.
// Background Script to close RITMs without triggering workflows or business rules
var ritmGR = new GlideRecord('sc_req_item'); // Table for RITMs
ritmGR.addQuery('state', '!=', '3'); // Skip already closed RITMs
//Add other queries as per your requirement using addQuery or addEncodedQuery
ritmGR.query();
while (ritmGR.next()) {
gs.print('Closing RITM: ' + ritmGR.number); // Log RITM number
ritmGR.setWorkflow(false); // Disable triggering of workflows
ritmGR.autoSysFields(false); // Suppress auto-updating system fields
ritmGR.state = '3'; // Set state to "Closed Complete" (state=3)
ritmGR.work_notes = 'Closed via background script without triggering further tasks.';
ritmGR.update(); // Save changes
}
gs.print('Script execution completed successfully.');
Please mark this answer as "Correct" and "Helpful" if this answer helped you in anyway.
Thanks and Regards,
K. Sai Charan
Sr. ServiceNow Developer
Deloitte India
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2024 08:09 AM
Thank you! So I can use this script and have another ritmGR.addQuery to only close the RITMs created in 2021 and 2022 and this should work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2024 08:29 AM
Hi @Brent Cox ,
Please add the below query in the script which I gave earlier to close ritms that were created on 2021 and 2022.
ritmGR.addEncodedQuery("sys_created_on>=2021-01-01^sys_created_on<2023-01-01"); // Filter for 2021 and 2022
Please mark this answer as Helpful and correct if it helped you in anyway
Thanks and Regards,
K. Sai Charan
Sr. ServiceNow Developer
Deloitte India
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2024 08:34 AM - edited ‎12-04-2024 08:50 AM
Hi @Brent Cox ,
Please make use of the below script to close the RITM's that were create on 2021 and 2022.
// Background Script to close RITMs without triggering workflows or business rules
var ritmGR = new GlideRecord('sc_req_item'); // Table for RITMs
ritmGR.addQuery('state', '!=', '3'); // Skip already closed RITMs
ritmGR.addEncodedQuery("sys_created_on>=2021-01-01^sys_created_on<2023-01-01"); // Filter for 2021 and 2022
//Add other queries as per your requirement using addQuery or addEncodedQuery
ritmGR.query();
while (ritmGR.next()) {
gs.print('Closing RITM: ' + ritmGR.number); // Log RITM number
ritmGR.setWorkflow(false); // Disable triggering of workflows
ritmGR.autoSysFields(false); // Suppress auto-updating system fields
ritmGR.state = '3'; // Set state to "Closed Complete" (state=3)
ritmGR.work_notes = 'Closed via background script without triggering further tasks.';
ritmGR.update(); // Save changes
}
gs.print('Script execution completed successfully.');
Please mark this answer as "Helpful" and "Correct" if it helped you in anyway
Thanks and Regards,
K. Sai Charan
Sr. ServiceNow Developer
Deloitte India