Autoclose ritm and request when all sctask closes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 06:38 AM
Hi
I have written a after business rule on sc_task table with condition as state is closed complete to autoclose ritm and requests but it is not checking for all the open sctasks from the flow and still the requests get closed
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var tasks = new GlideRecord('sc_task');
//tasks.addQuery('state', 'IN','3,4,7');
//tasks.addQuery('request_item.state','NOT IN','3,4,7');
tasks.addQuery('request_item',current.request_item);
tasks.addEncodedQuery('state=1^ORstate=2');
tasks.addActiveQuery();
//tasks.addQuery('state', '!=' , '3');
tasks.query();
if(tasks.next())
{
gs.addErrorMessage('There are open task records for this requested item. Please close all tasks.');
current.state=previous.state;
current.setAbortAction(true);
} else {
var rq = new GlideRecord('sc_req_item');
rq.addQuery('sys_id',current.request_item);
rq.query();
if(rq.next())
{
rq.state = 3;
rq.update();
}
}
var req = new GlideRecord('sc_request');
{ req.addQuery('sys_id', current.request);
req.query();
if(req.next())
{
req.state = 3; // check the state in your environment
req.request_state = 'closed_complete'; // check the state in your environment
req.update();
}
}})(current, previous);
The business rule doesnt wait for the flow to close all tasks generated
Please help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 08:21 AM
Hi @runda
If you are already have a Flow defined for your Requested Item process, it would be more recommended to achieve this also through flow instead of Business Rule.
After your flow closed all SC Tasks, than you check if all sc_tasks are closed for current RITM or not and accordingly update the state values of RITM and REQ.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2023 03:47 AM
But how can I add flow to all catlog items as we are creating many catlog items business rule will be global
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 12:44 PM
Just wondering did you ever get a solution for this issue and if you could share it, please?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 09:01 AM - edited 03-01-2023 09:01 AM
I haven't used flow yet for catalog items. I would think it works similar to workflow were once all the catalog tasks are closed you would set the state and stage of the ritm then out of the box business rules take care of the rest.