Close existing open Requests from Backgroun/Fix script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2023 12:48 PM
Hello Experts,
We have several requests that are in 'open' state but RITMs under those requests are already closed complete. So, I want to fix i.e. close those open requests. So, I am using below script in background script but no luck. Seeking help.
Background script:
var req = new GlideRecord('sc_request');
req.addActiveQuery();
req.query();
while (req.next()) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request',req.sys_id);
ritm.addEncodedQuery('state=3^request.state=1'); //where RITM is closed and REQUEST is open state.
ritm.setLimit(1);
}
if (ritm.next()) {
req.state = '3';
req.active = 'false';
req.setWorkflow('false');
req.stage = 'Completed';
req.autoSysFields();
req.update();
}
Thanks,
Rocky.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2023 07:05 PM - edited 04-03-2023 07:05 PM
Hello Bert,
Got it. My code is right but missing 'ritm.query();' line.
Thanks,
Rocky.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2023 07:07 AM
Hi Rocky5,
I also set field field values using syntax that matches their defined types. for example, booloean values allow true/false (no quotes) and integer values allow integer values (no quotes). For Choice fields, I use the value defined (you may have 'Completed' as a choice value for sc_request.stage, I do not have that in my instance. And changing where the closing "}" for the 'while' loop allowed all sc_request records that meet your conditions to be processed.
