- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2017 12:10 AM
Hi all,
I know this question has been asked several times and is covered on the wiki, but 'How to prevent an incident record being resolved or closed if a child task is still open'.
Sure I have done this fine in the past, and reread the below links:
http://wiki.servicenow.com/index.php?title=Prevent_Closure_if_Child_Task_is_Active#gsc.tab=0
https://community.servicenow.com/thread/279369
Prevent Incident Resolution When Tasks Are Still Open
Preventing Resolve or Close when Incident or Change Request has open Tasks
https://www.servicenowguru.com/scripting/stopping-record-submission-servicenow/
Don't close incidents when incident tasks are open
Which all use the same method of doing a glide over the child table using the parent (current) sys_id to check for active=true records, then using setAbortAction.
Code from my own 'before update' BR below, condition 'State changes to Resolved', order 100:
(function executeRule(current, previous /*null when async*/) {
var target = new GlideRecord('incident_task');
target.addQuery('active','true');
target.addQuery('parent',current.sys_id);
target.query();
if (target.next()) {
current.setWorkflow(false);
gs.addInfoMessage('Please close child task');
current.setAbortAction(true);
}
})(current, previous);
Except, in the customer instance, and my own OOTB local dev instance the state of the incident on the form still shows as Resolved to the user (but has not been saved to the database), and the close ui action is usable:
So I thought add a line of current.state = previous.state; in there, so at least the state is back to how it was before and although that fixes the state showing as resolved issue, the 'Close Incident' UI action is still there (extra bonus on the customer instance, the OOTB 'Caller Close' BR is also firing showing the message 'Incident xxx has been resolved).
Another idea was to add a line of gs.redirect(current); to force the form to reload, but that seemed to have no effect.
Then I found out there is a known error about using it in this way: ServiceNow KB: gs.setRedirect() in combination with current.setAbortAction(true) not executed (KB053...
My question is - has this changed in Jakarta so it no longer works? As on other threads I can see people using the exact same code for the same use case with no issue.
Or is there an alternative method?
Thanks
James
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2019 01:56 AM
Hi Ashutosh,
Just saw this is still open when logged in for something else.
I think towards the end of this thread I had raised it with ServiceNow, mainly so they update the example in the docs.
They replied back advising to use the below in a before BR, which worked:
(function executeRule(current, previous /*null when async*/) { var gr = new GlideRecord('incident_task'); gr.addQuery('active','true'); gr.addQuery('parent',current.sys_id); gr.query(); if (gr.next()) { gs.addInfoMessage('This Incident cannot be resolved as there is or are active child Incident Tasks. Please close them first'); //current.setWorkflow(false); >>> Use it only to prevent the message that the Incident has been resolved current.incident_state = previous.incident_state; // There are 2 Incident States and they need to be in sync. This one controls the display of the 'Close Incident' UI Action current.state = previous.state; // This is the displayed State field current.setAbortAction(true); gs.setRedirect(current); } })(current, previous);
I think either your example, or something I had done had worked before getting this reply anyway but posted here for anyone else who may find useful
Thanks
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2017 12:35 AM
ohk lets try to understand first how state changed to resolved on UI and not in DB (this may be because of BR working fine).
How are you resolving the incident ? using UI action? if Yes, that should have some client side scripting which needs to be handled.
or is there any other way?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2017 01:40 AM
if you are trying to resolve the incident from UI action (getting a strong feeling of UI action use );
you can write Business rule logic in same UI action in 2 ways:
1) when there are active child incident task ; dont show the UI action itself (can be handled in condition and with the help of script include)
or
2) if you want to show the UI action then check on if there are any child active incident task present (use same code as business rule) and if found, throw error message and terminate the transaction.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2017 02:54 AM
Hi again, was in a meeting.
Resolving the incident either via the state choice list, or the OOTB Resolve UI action have the same results - record on screen with the state of 'resolved', but a refresh shows it has not actually been set to resolved. So altering the UI action may fix for the button pushers but the customer instance also has the ability to use the choices.
ashutoshm1 - you mention an additional redirect on the current form so it gets refreshed, is this what I was trying to do with gs.redirect(current); but it has no impact.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2017 02:59 AM
Use SetRedirect.
Thank you,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2017 03:01 AM
In UI Action this is helpful:
action.setRedirectURL()