Close Parent Request if RITM has Complete and Cancelled Items

ivopetrow
Mega Contributor

Hello,

I have created a new business rule in order to change the parent request state to close when all

related RITMs are closed or canceled.

Please let me know if the script is ok

find_real_file.png

 

find_real_file.png

 

closeRequest();
function closeRequest(){

var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.request);
gr.addQuery('state', '!=', 3);
gr.query();
if (!gr.next()){
var sc_request = new GlideRecord('sc_request');
sc_request.addQuery('sys_id', current.request);
sc_request.query();
if (sc_request.next()){
sc_request.state = 3;
sc_request.update();
}
}
}

 

1 ACCEPTED SOLUTION

In workflow you can set the stage of an activity which then sets the stage attribute on the request item.  All of the out of the box examples use the "Completed" stage either on the end activity or just before the end activity.  Here is example from the procurement workflows:

find_real_file.png find_real_file.png

 

here is example from Service Catalog Item Request workflow:

find_real_file.png

 

Now changing your workflows won't address your existing 5000 records so a Fix script will be necessary to fix those.  But this will help with any new requests.

 

Please mark any post as helpful or the correct answer to your question if applicable so others viewing may benefit.

View solution in original post

5 REPLIES 5

SanjivMeher
Kilo Patron
Kilo Patron

You can improve the script to below. It should be an after BR. And you can add condition by saying Active Changes to False

 

closeRequest();
function closeRequest(){

var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.request);
gr.addQuery('active', 'true');
gr.query();
if (!gr.next()){
var sc_request = new GlideRecord('sc_request');
sc_request.addQuery('sys_id', current.request);
sc_request.query();
if (sc_request.next()){
sc_request.state = 3;
sc_request.update();
}
}
}


Please mark this response as correct or helpful if it assisted you with your question.

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

This is out of the box functionality.  There is a business rule called "Closed Parent if Required" that does this:

https://INSTANCENAME.service-now.com/nav_to.do?uri=sys_script.do?sys_id=596fac6bc0a8010a00dca5b76857e592

Since this is looking at the stage of the request all you need to do in your workflow is to make sure you set the stage to completed at the conclusion of your workflow.

Hi Michael,

The OOB business rule   "Closed Parent if Required" is already working but for some reason

it didn't work for more than 5000 incidents.

 

That's why i'm looking for a way to avoid such issues in future

Please can you provide more details on the below:

"Since this is looking at the stage of the request all you need to do in your workflow is to make sure you set the stage to completed at the conclusion of your workflow."

In workflow you can set the stage of an activity which then sets the stage attribute on the request item.  All of the out of the box examples use the "Completed" stage either on the end activity or just before the end activity.  Here is example from the procurement workflows:

find_real_file.png find_real_file.png

 

here is example from Service Catalog Item Request workflow:

find_real_file.png

 

Now changing your workflows won't address your existing 5000 records so a Fix script will be necessary to fix those.  But this will help with any new requests.

 

Please mark any post as helpful or the correct answer to your question if applicable so others viewing may benefit.