Business Rule to Set RITM & Request State to Closed Incomplete when RITM Stage is Request Cancelled

WazzaJC
Tera Expert

Business Rule to Set RITM & Request State to Closed Incomplete when RITM Stage is Request Cancelled

 

Hi ServiceNow Community colleagues,

 

Please can I ask for your advice on the Business Rule I would need to configure the following:

 

I would like to set the Requested Item (RITM) and Request 'State' to 'Closed Incomplete' after the RITM 'Stage' = Request Cancelled. The Request 'Stage' is currently being set to Request Cancelled in a Flow, but I want a business rule outside of the Flow, to auto-set the RITM and REQ State to Closed Incomplete.

 

So as soon as the RITM 'Stage' is = 'Request Cancelled', I want the Business Rule to set the RITM 'State' to 'Closed Incomplete' and also the corresponding Service Request 'State' to 'Closed Incomplete'.

 

Would anyone kindly be able to share the Script and Conditions I need to configure for this Business Rule - how would it look?

 

Thanks very much as always.

2 ACCEPTED SOLUTIONS

swathisarang98
Giga Sage
Giga Sage

Hi @WazzaJC ,

 

You can Try after update BR

Table: sc_req_item

condition as shown below,

Note: better to keep your catalog item in condition so that it will not run for others,

swathisarang98_0-1708643909495.png

 In action, to update requested item state

swathisarang98_1-1708643944868.png

In advanced, to update Request table

swathisarang98_0-1708669576242.png

code

(function executeRule(current, previous /*null when async*/) {

	var reqUpdate = new GlideRecord('sc_request');
	reqUpdate.addQuery('sys_id',current.request);
	reqUpdate.query();
	if(reqUpdate.next()){
		reqUpdate.state = 4 ;
		reqUpdate.request_state = 'closed_cancelled';
		reqUpdate.update();
	}

})(current, previous);

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

 

View solution in original post

Harish KM
Kilo Patron
Kilo Patron

Hi @WazzaJC there is OOB BR which does it when you cancel the RITM, Please check this BR on req item table

Close Parent if Required

Regards
Harish

View solution in original post

6 REPLIES 6

swathisarang98
Giga Sage
Giga Sage

Hi @WazzaJC ,

 

You can Try after update BR

Table: sc_req_item

condition as shown below,

Note: better to keep your catalog item in condition so that it will not run for others,

swathisarang98_0-1708643909495.png

 In action, to update requested item state

swathisarang98_1-1708643944868.png

In advanced, to update Request table

swathisarang98_0-1708669576242.png

code

(function executeRule(current, previous /*null when async*/) {

	var reqUpdate = new GlideRecord('sc_request');
	reqUpdate.addQuery('sys_id',current.request);
	reqUpdate.query();
	if(reqUpdate.next()){
		reqUpdate.state = 4 ;
		reqUpdate.request_state = 'closed_cancelled';
		reqUpdate.update();
	}

})(current, previous);

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

 

Hi @swathisarang98 . Thanks very much Swathi. This is great, it is Almost working for me. However, the RITM State is still going to 'Closed Complete' even with this Business Rule in place. I just do not understand why. The Request 'State' is correctly showing as 'Closed Incomplete' but not the RITM, that still stays/remains as 'Closed Complete'. Should I perhaps change the 'order' of the Business Rule, or should I make it After Insert and Update or Before Insert and Update. I am just thinking do I need to change any other conditions perhaps? Could it be conflicting with other Business Rules already existing in the system. I am just not sure why both RITM and REQ State are not both going to 'Closed Incomplete'. Let me know your thoughts/further advice, many thanks.

Hi @WazzaJC ,

 

Try changing the order if it works then fine, otherwise check BR on both request table and RITM table if you find any br with similar condition please send the screenshot ?

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

Thank you very much @swathisarang98 . Thanks to your help & suggested configuration, I have got the functionality to work, many thanks once again ! 🙂