We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to prevent users from closing an Incident if there are active Child Tasks? --

MOHAMEDYASA
Tera Contributor

How to prevent users from closing an Incident if there are active Child Tasks? using flow

2 ACCEPTED SOLUTIONS

Nayan ArchX
Tera Guru

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

View solution in original post

Aditya_hublikar
Mega Sage

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

View solution in original post

2 REPLIES 2

Nayan ArchX
Tera Guru

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

Aditya_hublikar
Mega Sage

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