Background script to close Requests when RITM is Closed complete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2019 02:07 AM
Hello Community,
As the title says; I could need some help writing a background script to close all our Requests when RITM have State Closed complete. We have approximately 130 Requests where RITM is Closed complete, so I believe there is a issue with a BR in our instance. I'm currently on the path of learning to write my own scripts, but unfortunately this is out of my skills.
Thanks in advance!
Best regards,
Adrian H
- Labels:
-
Service Desk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2019 02:42 AM
I would absolutely check this out - thank you a lot Mark!
I'll mark the correct answer when it's been replied.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2019 02:28 AM
Check out this:
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('state', '3'); // here value for Closed complete is 3, you can check what value you have
ritm.query();
while(ritm.next()){
gs.log("RITM Number: "+ritm.number);
// here you can use what you want to set for state or you can use ritm.setValue('state','value for closed') instead using below.
ritm.setDisplayValue('state','Closed');
ritm.active = false;
ritm.setWorkflow(false);
ritm.update();
}
Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies
Abhishek Gardade

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2019 02:29 AM
Try this
var req = new GlideRecord('sc_request');
req.addActiveQuery();
req.query();
while(req.next()){
// check if there are any active requested items under it
var req_item = new GlideRecord('sc_req_item');
req_item.addQuery('request',req.sys_id);
req_item.addActiveQuery();
req_item.setLimit(1);
if(req_item.next()){
// do nothing
}
else{
req.state = '3';
req.active = false;
req.setWorkflow(false);
req.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2019 02:34 AM
This is correct approach, this will work.
Just instead of if/else id use
if(!req_item.hasNext()){
req.state = '3';
req.active = false;
req.setWorkflow(false);
req.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2019 02:40 AM
Thanks all, I really appreciate all the answers!
However, we still have some Active Requests - so when I tried the script above it seems to be closing the active ones too. Just like