- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 12:04 PM
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
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();
}
}
}
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 01:30 PM
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:
here is example from Service Catalog Item Request workflow:
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 12:08 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 12:09 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 12:17 PM
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."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 01:30 PM
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:
here is example from Service Catalog Item Request workflow:
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.