- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2025 01:40 AM
How to Cancel Child Incidents if parent incident gets cancelled?
Please help with script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2025 01:43 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2025 01:43 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2025 01:46 AM
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2025 01:47 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2025 02:13 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader