Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

BR caused an error while updating the RITM to closure

Ananth11
Kilo Contributor

In a order guide we have mapped some catalog item. On submit of the request it will create Parent and Child RITM.

We have created a Business Rule(Auto closure of Req) which will trigger on Requested Item (sc_req_item) table(after insert ,Update)

This BR is used to auto close the request only If the request contains a particular catalog item and no other RITM's in open state.

In Flow designer we have created a flow to fulfill the request. While Close complete the RITM from flow we are getting below error.
The error because of the Business Rule I have mentioned above.

Error Message:
Error occured while updating record: Operation against file 'sc_req_item' was aborted by Business Rule 'commentslogging^8d2188688702c1101df1b8cd8bbb3529'. Business Rule Stack:commentslogging,Auto closure of Req

I request your help to fix the issue.

Business Rule Script:

var getRITM = new GlideRecord('sc_req_item');
getRITM.addActiveQuery();
getRITM.addQuery('request',current.request);
getRITM.query();
if(getRITM.next())
{

//Don't close REQ as One of the RITM Is open.
gs.addInfoMessage('REQ cant be closed because one of the RITM is Open');
current.setAbortAction(true);
}

else
{

var req = new GlideRecord('sc_request');
req.addQuery('sys_id',current.request);
req.query();

if(req.next())
{
req.request_state = 'closed_complete';//close complete the sc request state
req.stage = 'closed_complete';
req.update();
}
}

 

6 REPLIES 6

Ananth11
Kilo Contributor

The issue resolved when I used the above code and configuration. Thanks Ankur for your timely help

@Ananth 

Please mark my response as correct and close the thread.

Regards
Ankur

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