I want to write the Business rule for RITM State to update

PRAGHATIESH S
Tera Expert

Hi,

I written the BR on the Catalog task table, when catalog task state updated based on that RITM State also updated. But RITM got closed when one catalog task closed, it should need to wait till the last catalog task to close and update the RITM State.

 

Can any one help here

4 REPLIES 4

Bhavya11
Mega Patron

Hi @PRAGHATIESH S ,

 

 

instead of write Business rule, you can try flow/workflow. it will easy to sync the state of RITM ,SCTASK and REQ.

 

Thanks,

BK

Juhi Poddar
Kilo Patron

Hello @PRAGHATIESH S 

To ensure a RITM only closes after all associated Catalog Tasks are closed:

Business Rule Configuration

  • Table: sc_task
  • When to run: After insert or update
  • Condition: State is closed

Updated script in BR:

(function executeRule(current, previous /*null when async*/) {
    var ritm = new GlideRecord('sc_req_item');
    if (ritm.get(current.request_item)) {
        var tasks = new GlideRecord('sc_task');
        tasks.addQuery('request_item', ritm.sys_id);
        tasks.addQuery('state', '!=', 'closed'); // Adjust 'closed' as per your states
        tasks.query();

        if (!tasks.hasNext()) {
            ritm.state = 'closed'; // Adjust 'closed' as per RITM states
            ritm.update();
        }
    }
})(current, previous);

This will trigger when the state in sc_task is closed, checks for the ritm and check all the task associated with this RITM is closed. Then only update the RITM state to closed.

Note: Adjust closed state as per your requirement.

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar

 

 

AndersBGS
Tera Patron

Hi @PRAGHATIESH S ,

 

If the RITM close unintendedly you should look into the flow running in the background and not a business rule. 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders 

PrashantLearnIT
Tera Sage

Hi @PRAGHATIESH S 

 

Better make this logic change in Flow/Workflow as part of best practice, BR is not required here to sync states across REQ, RITM and SCTASK.