background script to close the ritm?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2019 10:54 PM
please someone provide me the background script to close only the targeted RITM records.
not all in sc_req_item table/ sc_request table
i will have a few RITM record numbers.
through background script i have to close only given RITM and REQ, not for remaining records or workflow.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2019 11:00 PM
try with below code. now you can add your ritm number which i had added some sample number.
var gr = new GlideRecord('sc_req_item');
gr.addQuery('number','IN','RITM0233941,RITM0233942,RITM02339413');
gr.query();
while(gr.next()){
gr.state= 3;
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2019 11:04 PM
Hi there,
Question: why would you like to close these records this way? I mean, if your workflow is setup correctly, the approval and tasks have been handled: the RITM should be closed automatically. When all RITM's have been handled, the REQ should be handled automatically.
So why scripting the closure?
Is this a one time thing?
Are they in a state Closed though the active flag still true?
Do you have a structural issue in your instance?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2019 11:05 PM
Hi,
try this background script to close RITM and request
also use setWorkflow(false) to avoid triggering any business rules on those 2 tables
you should have the list of RITM numbers with yo
var ritmRec = new GlideRecord('sc_req_item');
ritmRec.addQuery('number','IN','RITM000123,RITM000124,RITM000125');
ritmRec.query();
while(ritmRec.next()){
ritmRec.state= 3;
ritmRec.setWorkflow(false);
ritmRec.update();
var reqRefRecord = ritmRec.request.getRefRecord();
reqRefRecord.state = 3;
reqRefRecord.setWorkflow(false);
reqRefRecord.update();
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2020 04:36 PM
Good add on the workflow, I had this scenario based on a user rejecting the request in error which had several requested items in it.
Thanks again