- 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
06-12-2018 06:35 AM
Hi,
Can you mark answer as correct and close this thread.
Thanks,
Ashutosh
- 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:23 AM
Hi James,
1) How are you setting this state.
2) Is close incident button used to resolve or close?
Hope you are using UI Action in both the cases.
Thank you,
Ashutosh