- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2019 05:53 AM
I want to close all child incidents before closing parent incident, if any one child incident not closed the parent incident should not be close?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2019 07:08 AM
Hi Venkat,
Create an before update Business rule on incident table and add the condition as State changes to Resolved.
var rec = new GlideRecord('incident');
rec.addQuery('parent', current.sys_id);
rec.addQuery('state', 'IN', '1,2,3'); // Replace your incident state values like New, Work in progress, etc., except resolved or closed
rec.query();
if(rec.next()) {
gs.addErrorMessage("There is an active child incident, please resolve the child incident, before closing parent');
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2019 05:58 AM
Hi Venkat,
You can write the code below on the incident table, On-After Business Rule on Update.
var rec = new GlideRecord('incident');
rec.addQuery('parent', current.sys_id);
rec.query();
while (rec.next()) {
rec.state = 3; // Update to state value as needed
rec.update();
}
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2019 06:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2019 06:23 AM
Hi Venkat,
Write an OnSubmit Client Script and a script include as below:
Client Script :
var ga = new GlideAjax('CheckChild');
ga.addParam('sysparm_name', 'checkChildIncidents');
ga.addParam('sysparm_tablesysid', g_form.getUniqueValue());
ga.getXMLWait();
var children_status = ga.getAnswer();
if (children_status == 'true'){
return false;
}
else{
return true;
}
Script Include :
Var CheckChild= Class.create();
CheckChild.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkChildIncidents: function() {
//check if child Incidents exist
var gr = new GlideRecord('incident');
gr.addQuery('parent', this.getParameter('sysparm_tablesysid'));
//child incidents not closed
gr.addQuery('state', '!=', '3');
gr.query();
return gr.hasNext();
},
});
Mark If Correct/Helpful.
Regards,
Devyani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2019 07:08 AM
Hi Venkat,
Create an before update Business rule on incident table and add the condition as State changes to Resolved.
var rec = new GlideRecord('incident');
rec.addQuery('parent', current.sys_id);
rec.addQuery('state', 'IN', '1,2,3'); // Replace your incident state values like New, Work in progress, etc., except resolved or closed
rec.query();
if(rec.next()) {
gs.addErrorMessage("There is an active child incident, please resolve the child incident, before closing parent');
current.setAbortAction(true);
}