- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 10:01 PM
Hello Community,
I want to close the child incidents when i close parent incidents using Script?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 10:05 PM - edited 12-15-2023 10:06 PM
Hello @shadoworg
You need to Write Before Update BR Rule :-
if(current.state==closed complete){
var gr = new GlideRecord(‘incident’);
gr.addQuery(’parent’, current.sys_id);
gr.query();
while(gr.next()){
gr.state=‘closed complete’
gr.update();
}
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 10:05 PM - edited 12-15-2023 10:06 PM
Hello @shadoworg
You need to Write Before Update BR Rule :-
if(current.state==closed complete){
var gr = new GlideRecord(‘incident’);
gr.addQuery(’parent’, current.sys_id);
gr.query();
while(gr.next()){
gr.state=‘closed complete’
gr.update();
}
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 10:09 PM - edited 12-15-2023 10:10 PM
Hi @shadoworg ,
You can create a after update BR n add below script
(function executeRule(current, previous /*null when async*/) {
// Check if the current record is an Incident and has been closed
if (current.incident_state == '7') { // Assuming '7' is the closed state for incidents
// Query child incidents
var childIncident = new GlideRecord('incident');
childIncident.addQuery('parent', current.sys_id);
childIncident.query();
// Loop through child incidents and close them
while (childIncident.next()) {
childIncident.incident_state = '7'; // Set to the closed state
childIncident.update();
}
}
})(current, previous);
Please use proper backend values wherever required.
Thanks,
Danish