Business Rule on RITM

akash12345
Tera Contributor

Need to add BR on RITM  for verifying all the catalog task are closed then only RITM will be closed.

3 REPLIES 3

AshishKM
Kilo Patron
Kilo Patron

Hi @akash12345 ,

Why you need to check this externally, do you have some ad-hoc task which are created outside of running workflow. If yes, then you should apply logic within the specific workflow only. OOTB the running workflow does this check and end after all tasks are closed ( if configured properly ).

 

Describe the use case in details here, we should not configure the BR just for few catalog item issues as this BR will run on every RITM where it's not needed.

 

-Thanks,

AshishKMishra

 

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Bphan
Tera Contributor

HI @akash12345 

You can using after update BR to check State change to Resolved or closed

 

(function executeRule(current, previous /*null when async*/ ) {
    //Check if there is any unresolved catalog task status
    //Set flag is true if found any unresolved catalog task status and no action
    //If all catalog are resolved, the requested item will be resolved
        var _flag = false;
        var gr_scTask = new GlideRecord('sc_task');
        gr_scTask.addActiveQuery();
        gr_scTask.addQuery('request_item', current.request_item);
        gr_scTask.addQuery('state', '!=', 5); //Resolved
        gr_scTask.addQuery('state', '!=', 9); // Cancelled
        gr_scTask.query();
        if (gr_scTask.hasNext()) {
            _flag = true;
        } else {
            var gr_scReqItem = new GlideRecord('sc_req_item');
            gr_scReqItem.addActiveQuery();
            gr_scReqItem.addQuery('sys_id', current.request_item);
            gr_scReqItem.query();
            if (gr_scReqItem.next()) {
                gr_scReqItem.state = '5'; //Resolved
                gr_scReqItem.stage = 'Resolved';
                gr_scReqItem.update();
            }
        }
})(current, previous);

Please mark this response as correct and helpful if it helps you

 

Thanks and best regards,
Bach Phan

Ankur Bawiskar
Tera Patron
Tera Patron

@akash12345 

usually we don't close RITM manually.

RITM should ideally get closed once all catalog tasks associated to that RITM is completed.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader