Parent and child Incident relationship

Prabhat4
Tera Contributor

I want to establish Connection between parent incident and child incident (Parent incident field is present on incident form).

Whenever any incident is updated as parent of 'N' numbers of incident then all the child should be updated with worknotes that "INC***   has been updated as parent of this incident and for future updates please refer to parent incident". Moreover whenever i'll close the parent then all the child should also get close with same assigned to and assignment group values & with couple of more selected values. please advise how i can achieve this through Business rule.

Thanks

Prabhat

1 ACCEPTED SOLUTION

Michael Fry1
Kilo Patron

The business rule Update Child Incidents is the rule that updates Child incidents when the parent is updated or resolved. In order to achieve your requirement - ...whenever i'll close the parent then all the child should also get close with same assigned to and assignment group values & with couple of more selected values... - you'll have to modify the resolveChildIncidents section. See below:




function resolveChildIncidents() {


      var incident = new GlideRecord("incident");


      incident.addActiveQuery();


      incident.addQuery("parent_incident", current.sys_id);


      incident.addQuery("incident_state", "!=", IncidentState.RESOLVED);


      incident.query();


      var msg = "";


      while (incident.next()) {


              gs.print("Incident " + incident.number + ' resolved based on resolution of Parent Incident ' + current.number);


              incident.incident_state = IncidentState.RESOLVED;


              if (incident.close_notes.nil()) {


                      msg = "Close notes copied from Parent Incident";


                      if (current.close_notes.toString().indexOf(msg) == 0)


                              incident.close_notes = current.close_notes;


                      else


                              incident.close_notes = msg + ": " + current.close_notes;


              }


              incident.close_code = current.close_code;


              msg = "Resolved based on resolution of Parent Incident.";


              if (current.comments.toString().indexOf(msg) == 0)


                      incident.comments = current.comments;


              else


                      incident.comments = msg + " " + current.comments;


              incident.work_notes = current.work_notes;


//add new code here to set assignment group and assigned to


incident.assignment_group = current.assignment_group;


incident.assigned_to = current.assigned_to;


//add more values here as needed



              incident.update();


      }


View solution in original post

7 REPLIES 7

sb1186
Kilo Guru

Hi Prabhat,



Not sure if you have already checked, but there is an OOB Business Rule available in the system which fulfils both your requirements.


The Business Rule is Update Child Incidents. As per this Business Rule, a child incident would be updated whenever:


1) Additional Comments on parent incident are updated


2) Work Notes on parent incident are updated


3) Status of parent incident changes to Resolved, it resolves all associated child incidents as well



PS: Mark this answer as Correct if it solved your query or hit Like/Helpful depending upon the usefulness of the response.



Regards,


Supriya Bisht


Michael Fry1
Kilo Patron

The business rule Update Child Incidents is the rule that updates Child incidents when the parent is updated or resolved. In order to achieve your requirement - ...whenever i'll close the parent then all the child should also get close with same assigned to and assignment group values & with couple of more selected values... - you'll have to modify the resolveChildIncidents section. See below:




function resolveChildIncidents() {


      var incident = new GlideRecord("incident");


      incident.addActiveQuery();


      incident.addQuery("parent_incident", current.sys_id);


      incident.addQuery("incident_state", "!=", IncidentState.RESOLVED);


      incident.query();


      var msg = "";


      while (incident.next()) {


              gs.print("Incident " + incident.number + ' resolved based on resolution of Parent Incident ' + current.number);


              incident.incident_state = IncidentState.RESOLVED;


              if (incident.close_notes.nil()) {


                      msg = "Close notes copied from Parent Incident";


                      if (current.close_notes.toString().indexOf(msg) == 0)


                              incident.close_notes = current.close_notes;


                      else


                              incident.close_notes = msg + ": " + current.close_notes;


              }


              incident.close_code = current.close_code;


              msg = "Resolved based on resolution of Parent Incident.";


              if (current.comments.toString().indexOf(msg) == 0)


                      incident.comments = current.comments;


              else


                      incident.comments = msg + " " + current.comments;


              incident.work_notes = current.work_notes;


//add new code here to set assignment group and assigned to


incident.assignment_group = current.assignment_group;


incident.assigned_to = current.assigned_to;


//add more values here as needed



              incident.update();


      }


Hi Michael,



Thanks for the answer, however currently i'm not able to achieve this condition. i've added my conditions and fields in code but it is not working properly.



This is the code i have used:


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


function resolveChildIncidents() {


var incident = new GlideRecord("incident");


incident.addActiveQuery();


incident.addQuery("parent_incident", current.sys_id);


incident.addQuery("incident_state", "!=", "6");


incident.query();


var msg = "";


while (incident.next()) {


gs.print("Incident " + incident.number + ' resolved based on resolution of Parent Incident ' + current.number);


incident.incident_state = 6;


if (incident.close_notes.nil()) {


msg = "Close notes copied from Parent Incident";


if (current.close_notes.toString().indexOf(msg) == 0)


incident.close_notes = current.close_notes;


else


incident.close_notes = msg + ": " + current.close_notes;


}


incident.close_code = current.close_code;


msg = "Resolved based on resolution of Parent Incident.";


if (current.comments.toString().indexOf(msg) == 0)


incident.comments = current.comments;


else


incident.comments = msg + " " + current.comments;


incident.work_notes = current.work_notes;


incident.assignment_group = current.assignment_group; // this code is not working !!!


incident.assigned_to = current.assigned_to;


incident.priority = current.priority;


incident.impact = current.impact;



incident.update();


}


}


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


Thanks


Prabhat


Just this one line isn't working: incident.assignment_group = current.assignment_group; // this code is not working !!!


or the code in bold isn't working?