- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
How to prevent users from closing an Incident if there are active Child Tasks? using flow
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
Prevent users from setting an Incident to Closed if any Child Tasks are still active.
(Child Tasks = records in task / incident_task / custom task tables with parent = incident and state ≠ Closed.)
Flow alone cannot block a save — it runs after the update.
The correct design should be:
🔐 Business Rule = Hard Stop
🤖 Flow = Friendly Message / Automation
Create Before Update Business Rule
Table - Incident
When - Before Update
Condition - State changes to Closed
Script:
(function executeRule(current, previous) {
var gr = new GlideRecord('incident_task'); // or task if mixed
gr.addQuery('parent', current.sys_id);
gr.addQuery('state', '!=', 3); // 3 = Closed (adjust if needed)
gr.query();
if (gr.hasNext()) {
gs.addErrorMessage('You cannot close this Incident while Child Tasks are still active.');
current.setAbortAction(true);
}
})();
✅ Result
User clicks Close →
System blocks →
Clear error message →
Incident remains open.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks
Nayan Patel
IT ServiceNow Consult, ServiceNow ArchX
If my response has resolved your query, please mark it Helpful by giving it a thumbs up and Accept the Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @MOHAMEDYASA ,
By flow it it not possible, You can use Business rule
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('incident_task');
gr.addQuery('incident', current.sys_id);
gr.query();
while (gr.next()) {
if (gr.state != 4 && gr.state != 3 && gr.state != 7) {
gs.addErrorMessage("Please close all incident tasks first!!");
current.setAbortAction(true);
break; // stop loop once condition met
}
}
// Add your code here
})(current, previous);
Condition : state changes to resolved
before update business rule
If this helps you then you can mark it as helpful and accept as solution.
Regards,
Aditya,
Technical Consultant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
Prevent users from setting an Incident to Closed if any Child Tasks are still active.
(Child Tasks = records in task / incident_task / custom task tables with parent = incident and state ≠ Closed.)
Flow alone cannot block a save — it runs after the update.
The correct design should be:
🔐 Business Rule = Hard Stop
🤖 Flow = Friendly Message / Automation
Create Before Update Business Rule
Table - Incident
When - Before Update
Condition - State changes to Closed
Script:
(function executeRule(current, previous) {
var gr = new GlideRecord('incident_task'); // or task if mixed
gr.addQuery('parent', current.sys_id);
gr.addQuery('state', '!=', 3); // 3 = Closed (adjust if needed)
gr.query();
if (gr.hasNext()) {
gs.addErrorMessage('You cannot close this Incident while Child Tasks are still active.');
current.setAbortAction(true);
}
})();
✅ Result
User clicks Close →
System blocks →
Clear error message →
Incident remains open.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks
Nayan Patel
IT ServiceNow Consult, ServiceNow ArchX
If my response has resolved your query, please mark it Helpful by giving it a thumbs up and Accept the Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @MOHAMEDYASA ,
By flow it it not possible, You can use Business rule
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('incident_task');
gr.addQuery('incident', current.sys_id);
gr.query();
while (gr.next()) {
if (gr.state != 4 && gr.state != 3 && gr.state != 7) {
gs.addErrorMessage("Please close all incident tasks first!!");
current.setAbortAction(true);
break; // stop loop once condition met
}
}
// Add your code here
})(current, previous);
Condition : state changes to resolved
before update business rule
If this helps you then you can mark it as helpful and accept as solution.
Regards,
Aditya,
Technical Consultant

