Incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago
1)Restrict the incident resolution if any incident task is in progress
If user try to resolve the incident system should validate all incident task should be closed
If any incident task is in in progress state restrict the incident to resolved
Display Error message : The following child incident is opened(incident number)
Close the child incident before resolve the child incident.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago
@MahalakshmiN543 You need to create a business rule on the incident table with following configuration.
Table: Incident [incident]
When: before
Insert / Update: Check Update
Filter Conditions: State | changes to | Resolved
Script:
(function executeRule(current, previous /*null when async*/) {
// Query for any open Incident Tasks under this Incident
var taskGr = new GlideRecord('incident_task');
taskGr.addQuery('incident', current.getUniqueValue());
// Active tasks or tasks not closed/canceled
taskGr.addQuery('state', 'IN', '1,2'); // Adjust state values (e.g., 1=New, 2=In Progress) based on your instance configuration
taskGr.query();
var openTasks = [];
while (taskGr.next()) {
openTasks.push(taskGr.getValue('number'));
}
if (openTasks.length > 0) {
// Abort the save operation
current.setAbortAction(true);
// Display error message
gs.addErrorMessage('The following incident task is opened: ' + openTasks.join(', ') + '. Close the incident task before resolving the incident.');
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago
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);
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago
You need to create before BR on Incident table with condition : State changes to Resolved. It needs to run on Update. Please click on Advanced and write below script
(function executeRule(current, previous /*null when async*/) {
// Query all non-closed Incident Tasks linked to this Incident
var taskGR = new GlideRecord('incident_task');
taskGR.addQuery('incident', current.sys_id);
taskGR.addQuery('state', '!=', 3); // 3 = Closed; catches Open (1) and In Progress (2)
taskGR.orderBy('number');
taskGR.query();
if (taskGR.hasNext()) {
var openTaskNumbers = [];
while (taskGR.next()) {
openTaskNumbers.push(taskGR.number.toString());
}
// Block the update and surface the error to the user
current.setAbortAction(true);
gs.addErrorMessage(
'The following child incident task(s) are open: ' +
openTaskNumbers.join(', ') +
'. Please close the child incident task(s) before resolving this incident.'
);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
Hi @MahalakshmiN543,
Use - Before Business Rule - Update
Filter Condition: State - Changes to - Resolved
Script:
(function executeRule(current, previous /*null when async*/ ) {
var childIncidents = new GlideRecord('incident_task');
childIncidents.addQuery('incident', current.sys_id);
childIncidents.addQuery('state', '!=', 3);
childIncidents.query();
if (childIncidents.hasNext()) {
var incTasks = [];
while (childIncidents.next()) {
incTasks.push(childIncidents.number.toString());
}
gs.addErrorMessage('The following child incidents are still in progress: ' + incTasks.join(', ') + ' - Close the child incident before resolve the child incident.');
current.setAbortAction(true);
}
})(current, previous);