Closing Incidents
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
We need to make a change so that Incidents cannot be closed if they have open incident tasks. We have learned that users are closing incidents before others close out the incident tasks assigned to them. This results in the incident task being closed as incomplete.
Can someone point me in the right direction for where this logic lives so that I can make a change?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
You may need to implement BR on incident table when someone try to resolve incident to check if there is any active incident task. bellow is sample script.
(function executeRule(current, previous /*null when async*/) {
// Query the Incident Task table for any open/active tasks tied to this incident
var taskGr = new GlideRecord('incident_task');
taskGr.addQuery('incident', current.sys_id);
taskGr.addActiveQuery(); // Checks for active = true
taskGr.query();
if (taskGr.hasNext()) {
// Prevent the incident from being closed/resolved
current.setAbortAction(true);
// Display the user-friendly suggestion/warning
gs.addErrorMessage('You cannot close this incident while there are open incident tasks. Please close all related incident tasks before closing the incident.');
}
})(current, previous);
Please mark my answer correct and helpful if this works for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @sseverance
you can create a Before-Update Business Rule on the incident table. This script queries the incident_task table for any open records linked to the parent Incident and stops the closure process if found.
- Navigate to System Definition > Business Rules and click New.
- Fill out the form with the following details:
- Name: Prevent Incident Closure with Open Tasks
- Table: Incident
- Active: Checked
- Advanced: Checked
- Go to the When to run tab and set the filter conditions:
State changes to Closed ( depending on your business process)
Script:
(function executeRule(current, previous /*null when async*/) {
// Query the incident_task table for tasks related to this incident that are not closed
var task = new GlideRecord('incident_task');
task.addQuery('incident', current.sys_id); // Links to the parent incident
task.addEncodedQuery('stateNOT IN3,4,7');
task.query();
// If open tasks exist, abort the save and show an error message
if (task.hasNext()) {
gs.addErrorMessage('You cannot close this Incident because it has open Incident Tasks. Please close all related tasks first.');
current.setAbortAction(true);
}
})(current, previous);
4.Save and test it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @sseverance
Create a Before Update BR and try this:
Navigate to System Definition > Business Rules -> New
Fill out the form with the following details:
- Name: Prevent close with open tasks
- Table: Incident [incident]
- Active: Checked
- Advanced: Checked
- When to run:
- When: Before
- Update: Checked
- Filter Condition: State changes to Resolved OR State changes to Closed //update your required condition
Sample script:
(function executeRule(current, previous /*null when async*/) {
var taskGr = new GlideRecord('incident_task');
taskGr.addQuery('incident', current.sys_id);
taskGr.addQuery('active', true);
taskGr.query();
if (taskGr.hasNext()) {
current.setAbortAction(true);
gs.addErrorMessage(gs.getMessage('You cannot close or resolve this Incident because there are still open Incident Tasks. Please close all tasks first.'));
}
})(current, previous);
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @sseverance ,
You can acheived this using before update business rule :
condition : state changes to closed / resolve
var incTask=new GlideRecord('incident_task');
incTask.addQuery("incident",current.sys_id);
incTask.query();
while(incTask.next())
{
if(incTask.state!=3 || incTask.state!=4)
{
current.setAbortAction(true);
gs.addErrorMessage('Incident taska are not completed ')
break;
}
}
if this helps you then mark it as helpful and accept as solution.
Regards,
Aditya