Cancel Child Incidents if parent incident gets cancelled

kushagra05
Tera Contributor

How to Cancel Child Incidents if parent incident gets cancelled?

Please help with script.

1 ACCEPTED SOLUTION

amitshishod
Tera Guru

Hello @kushagra05 ,

You can use after update Business rule on incident table and filter condition will be "State changes to cancelled".

 

Below is the script

var inc = new GlideRecord("incident"); 

    inc.addEncodedQuery("parent_incident=" + current.sys_id); // To query child incidents

    inc.query();

    while(inc.next()){

        inc.state = 8;

        inc.update();

    }

Please mark my answer correct and helpful if it helps you.

View solution in original post

4 REPLIES 4

amitshishod
Tera Guru

Hello @kushagra05 ,

You can use after update Business rule on incident table and filter condition will be "State changes to cancelled".

 

Below is the script

var inc = new GlideRecord("incident"); 

    inc.addEncodedQuery("parent_incident=" + current.sys_id); // To query child incidents

    inc.query();

    while(inc.next()){

        inc.state = 8;

        inc.update();

    }

Please mark my answer correct and helpful if it helps you.

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @kushagra05 

 

Ootb there is BR which sync parent and child Incident state , you can add cancel as well there.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Abhishek_Thakur
Mega Sage

Hello @kushagra05 ,

Please write a business rule and utilize the below script to cancel the parent incident if, child incident gets cancelled.

(function executeRule(current, previous /*null when async*/) {
    // Check if the incident is a parent and is being canceled
    if (current.parent == ''" || current.parent == null) {
        // Query all child incidents
        var grChildIncidents = new GlideRecord('incident');
        grChildIncidents.addQuery('parent', current.sys_id); // Match parent sys_id
        grChildIncidents.addActiveQuery(); // Only active incidents
        grChildIncidents.query();
 
        while (grChildIncidents.next()) {
            // Set state to Cancelled
            grChildIncidents.state = current.state; // Match the parent's canceled state
            grChildIncidents.update();
        }
    }
})(current, previous);

 

Please mark my answer as accepted solution and give thumbs up, if it helps you.

Regards,

Abhishek Thakur

Ankur Bawiskar
Tera Patron
Tera Patron

@kushagra05 

you can use flow designer for this with no script

OR

after update BR on incident table with condition as State [Changes to] Cancelled

var inc = new GlideRecord("incident");
inc.addActiveQuery();
inc.addQuery("parent_incident", current.getUniqueValue());
inc.query();
inc.setValue('state', 8);
inc.updateMultiple();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader