Incident management

Pavan rishi
Tera Contributor

How to automatically set the incident to a closed state when a child incident is resolved or a problem is created?

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @Pavan rishi,

 

Whilst what you're requesting could be implemented via a Business Rule, from a Process perspective and best practice, I would encourage you to review and question the requirement.

(It's a case of just because something can be done, it doesn't mean it should).

 

When a child incident is created, whilst it is related, the process is synchronized by the Parent Incident to Child Incident, not the other way around. Additionally, should multiple incidents be created and associated, this also needs to be factored in, hence the parent relationship synchronization.

 

See the following link: https://www.servicenow.com/docs/bundle/xanadu-it-service-management/page/product/incident-management...

 

Another point to note, an incident should be Resolved primarily giving the caller the ability to Accept or Reject the Resolution. OOB (Out Of Box) an incident will be auto closed if no response or acknowledgement is received when an Incident is Resolved.

Please note however, the child Incident will also follow this Resolution process and may also requires confirmation from the caller or auto closure.

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.




Thanks, Robbie

View solution in original post

6 REPLIES 6

Runjay Patel
Giga Sage

Hi @Pavan rishi ,

 

As mentioned by @Dr Atul G- LNG , there is one oob configuration which close the incident after 7 days of incident resolution. If you want to close it immediately then you need to write BR on incident and problem table like below.

for child incident closer:

if (current.state == 6) { // Check if the child incident is resolved (State 6 is "Resolved")
    var parentIncident = current.parent; // Reference to the parent incident
    if (parentIncident) {
        var parentRecord = new GlideRecord('incident');
        if (parentRecord.get(parentIncident)) {
            parentRecord.state = 7; // Set to "Closed" (State 7 is "Closed")
            parentRecord.update();
        }
    }
}

 

For problem created:

var incidentGr = new GlideRecord('incident');
if (incidentGr.get(current.parent)) { // Assuming correlation_id links the problem to the incident
    incidentGr.state = 7; // Set to "Closed"
    incidentGr.close_code = 'Closed/Resolved by Problem'; // Add a relevant close code
    incidentGr.close_notes = 'Closed because a problem was created.';
    incidentGr.update();
}

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

yuvarajkate
Giga Guru

If Child Incident is resolved use After BR on Incident table.

if (current.parent) {
    var parent = new GlideRecord('incident');
    if (parent .get(current.parent)) {
        var Child = new GlideRecord('incident');
        child .addQuery('parent', current.parent);
        child .addQuery('incident_state', '!=', 6); 
        child .query();
        if (!child .hasNext()) {
            parent.state = 7; 
            parent.update();
        }
    }
}

  

If Problem is Created use this one:

if (current.parent_incident) {
    var inc = new GlideRecord('incident');
    if (inc .get(current.parent_incident)) {
        inc .state = 7; 
        inc .update();
    }
}