Prevent Incident Resolution When Tasks Are Still Open

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2015 01:58 PM
We have a need to provide the ability to create Incident Tasks for our Applications Team, as they often divide up work when addressing an incident. As discussed in many other incident task discussions, we've taken the advice given and extended the Task Table to create Incident Tasks. The applications team can now create Incident Tasks without issue; however, they are Resolving Incidents without closing their tasks. We would like to do a check to prevent this by displaying a message when they set the Incident state to Resolved if there are Open Tasks. Initially, we attempted to do this with a Business Rule, without scripting and just using a filter in the Business Rule. It appears this would work, if I was able to set When To Run with a Filter Condition on Incident when State changes to Resolved and select the Incident Task table and filter on Active or State = Open. Is this possible to execute a Business Rule on the Incident table and filter on both the Incident table and Incident Task table by dot walking? For some reason, I am unable to select the Incident Task table and fields. Thanks!
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017 03:40 PM
What am I missing - not having any luck with the script.
Business Rule:
Table: Incident_Task
When to Run: Before and Update
Conditions: current.incident_state == IncidentState.RESOLVED
function onBefore(current, previous) {
var target = new GlideRecord('incident_task');
// table name for your Incident task
target.addQuery('incident', current.sys_id);
//this is the field which will link Incident to Incident task
//search for open Incident tasks
target.addQuery('state', 1).addOrCondition('state', 2).addOrCondition('state', -5);
// check for open Incident task - add/edit states integer values as appropriate
target.query();
if(target.hasNext()){
if ((current.incident_state == 6) || (incident.problem_state == 7)){
gs.addInfoMessage("You have open tasks which must be completed before this record can be closed");
current.setAbortAction(true);
}
}
}
The End Result I am looking for is for a Alert message and for the Incident not to Resolve unless all Incident Task are Closed.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2017 01:12 AM
You can look at replacing the below line with a query to check only for 'active=true' incident tasks.
target.addQuery('state', 1).addOrCondition('state', 2).addOrCondition('state', -5);
Also, I think it makes sense to hide the button if the incident has some related tasks that are active. Why do we need to show the user a button if is not actionable? You can add a info message on top of the form if the incident has tasks so that people are not confused on the unavailability of the button. Hope that helped!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2015 07:47 PM
you could edit the UI Action (button) to run a query of the incident task table and if there are some open, then alert the user this incident cannot be closed until all children have been resolved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017 10:59 PM
Hi,
To prevent the Parent incident Record being Closed if the Child Records are still open, you can write a Before Update Business Rule on The Incident Table
Script:
Give the Filter Conditions as "State ChangesTo Resolved"
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('incident_task');
gr.addQuery('active','true');
gr.addQuery('incident',current.sys_id);
gr.query();
if (gr.next()) {
gs.addInfoMessage(('Please Close all the Incident Tasks before Resolving the Incident'));
current.state = previous.state;
current.setAbortAction(true);
}
})(current, previous);
Hope this helps.Mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2017 12:27 PM
I used this script and I see the addInfoMessage indicating the GlideRecord is testing true for an open incident_task but the state field remains Resolved. Is there a way to reload the form so that the State field reflects the previous.state which for us is Pending Tasks? I have read there is a bug that prevents gs.setRedirect(current.getLink(true)); when using current.setAbortAction(true);. Is this what is preventing the page reload if so I will propmpt users to manually reload page with a message.