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?

VENKATESH PUNGA
Tera Contributor

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? 

1 ACCEPTED SOLUTION

vinothkumar
Tera Guru

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);
}

View solution in original post

5 REPLIES 5

harishdasari
Tera Guru

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.

 

VENKATESH PUNGA
Tera Contributor
Hi harish, Thanks for your quick reply, but I don't want update child incidents, just simply when ever all child incidents closed then only parent record allows to close the state until parent incident should be same state only. Thanks, Venkat

Devyani_6
Mega Guru

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

vinothkumar
Tera Guru

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);
}