Request is still active even when the RITMs are closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2025 04:09 AM
I want to close the active requests for which the RITMs are closed, complete or incomplete, using the background script. Can anyone please help me with the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2025 04:13 AM
Hi @GBS
You can do via list view as well, instead of doing via script.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2025 04:17 AM
this will help, please enhance it further
closeRequest();
function closeRequest() {
try {
// Define the GlideRecord for the Request table
var grRequest = new GlideRecord('sc_request');
grRequest.addActiveQuery() // Only active requests
grRequest.query();
while (grRequest.next()) {
// Define the GlideRecord for the RITM table
var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('request', grRequest.sys_id);
grRITM.addEncodedQuery('stateIN3,4,7'); // Closed, Complete, or Incomplete states
grRITM.query();
var allRITMsClosed = true;
while (grRITM.next()) {
if (grRITM.state != 3 && grRITM.state != 4 && grRITM.state != 7) {
allRITMsClosed = false;
break;
}
}
if (allRITMsClosed) {
grRequest.active = false;
grRequest.state = 3; // Closed state
grRequest.update();
gs.info('Closed request: ' + grRequest.number);
}
}
} catch (ex) {
gs.info(ex);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2025 05:00 AM
@Ankur Bawiskar will this script close the RITMs which are open?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2025 05:02 AM
nope
As per your question you asked to close open REQ if all RITMs under it are closed, so I shared the script accordingly
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader