- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 01:14 AM
Hi All,
I am using below code to check the child incident state before closing parent incident , but the code is not working , someone please check and suggest the code changes
i am making the parent incidents state to resolved , instead of abort the state value is setting to resolved
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 01:53 AM
your business rule should be of type Before update
use this script with some minor change
var gr = new GlideRecord('incident');
gr.addQuery('parent_incident', current.sys_id);
gr.addQuery('stateNOT IN6,7');
gr.query();
if (gr.hasNext()) {
gs.addErrorMessage('please close child incidents before clsong parent incident');
current.setAbortAction(true);
current.state = previous.state;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 01:40 AM
Hello @shabbir5 ,
Remove the "current.state=previous.state;" from code and try below Before business rule:
When to run:
Advance :
var gr = new GlideRecord('incident');
gr.addQuery('parent_incident', current.sys_id);
gr.addQuery('stateNOT IN6,7');
gr.query();
while (gr.next()) {
gs.addErrorMessage('please close child incidents before clsong parent incident');
current.setAbortAction(true);
}
If this solution helped resolve your issue, please consider marking it as helpful or correct.
This will assist others in finding the solution faster and close the thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 01:42 AM
Refresh the page if the updated state is shown. Sometimes due to cache it displace the other states but is not updated in the database in actual.
If this solution helped resolve your issue, please consider marking it as helpful or correct.
This will assist others in finding the solution faster and close the thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 01:45 AM
Hello @shabbir5, Can you please verify whether BR is configured to run 'Before' 'Update'? If you have configured as stated, can you share the complete screenshot of Business Rule?
Regards,
Nishant

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 01:50 AM
Hi Nishant,
Can you try below.
var gr = new GlideRecord('incident');
gr.addQuery('parent_incident', current.sys_id);
gr.addQuery('stateNOT IN6,7');
gr.query();
if (gr.next()) {
gs.addErrorMessage('please close child incidents before clsong parent incident');
current.setAbortAction(true);
action.setRedirectURL(current);
current.state=previous.state;
}