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:47 AM
The above script will close all requests that are active and has no active ritm.
setWorkflow(false) -> This will ensure that when the request is being closed by the script, no other business rules run for that transaction.
What do you want to exclude from the logic, what requests should not be closed?
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2019 02:50 AM
Some of our requests still have active RITMs with state Limited acces, which means it will be Closed complete on a specific date. Requests like these has to remain active, so it's only requests where RITMs are Closed complete (3) we want to close.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2019 03:01 AM
Ok,
Try this then
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.addQuery('state', 3);
req_item.setLimit(1);
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 03:57 AM
It seems it still took the Active ones. Any other suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2019 04:06 AM
Lets try the reverse
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.addQuery('state','!=', 3);
req_item.setLimit(1);
if(!req_item.next()){
req.state = '3';
req.active = false;
req.setWorkflow(false);
req.update();
}
}
Now, if there are any ritm under the req which is not closed complete, then no action, else it will close the req