Using BR automatically close the associated incident when the problem is closed.

kranthi2
Tera Expert

Hi,

Using BR automatically close the associated incident when the problem is closed.

 

Kindly help me out the BR for the same.

Thanks,

2 REPLIES 2

NagaChandaE
Kilo Sage

Hi @kranthi2 

 

Write a After update Business Rule on problem table 

and Add a condition to check if the state of the problem is changing to Closed.

In Code:

 

(function executeRule(current, previous) {
    var incidentGr = new GlideRecord('incident'); 
    incidentGr.addQuery('problem_id', current.sys_id);
    incidentGr.addQuery('state', '!=', 'Closed');
    incidentGr.query();

    while (incidentGr.next()) {
        incidentGr.state = 7;
        incidentGr.close_code = 'Closed/Resolved by Problem';
        incidentGr.close_notes = 'Closed because the associated problem was resolved.';
        incidentGr.update();
    }
})(current, previous);

 

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Naga Chandan

 

Juhi Poddar
Kilo Patron

Hello @kranthi2 

To meet the requirement create an After update business rule on:

Table: Problem

condition state is closed.

BR Script:

 

(function executeRule(current, previous /*null when async*/) {
    // Check if the problem is closed (replace 'state' with your actual field if it's different)
    if (current.state == 6) { // Assuming 6 is the "Closed" state value
        // GlideRecord to find the associated incident
        var grIncident = new GlideRecord('incident');
        
        // Query the incident that is linked to the problem
        grIncident.addQuery('problem_id', current.sys_id);
        grIncident.query();
        
        // If an associated incident is found
        while(grIncident.next()) {
            // Use setValue to set the state of the incident to closed
            grIncident.setValue('state', 6); // 6 being the "Closed" state value
            grIncident.update();  // Save the incident
        }
    }
})(current, previous);

 

The provided script will close all incidents associated with a particular problem record when the problem is closed.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar