Problem Closure and Related Incidents

tomcamish
Kilo Contributor

Hi All,

My business requirement specifies that incidents/problems are set to Resolved to await caller feedback, at which point the incident/problem is set to Closed if the caller selects close in the email they receive (the email bit isnt set up yet).

I currently have a script that, when a problem is set to "Resolved", the related incidents also get set to "Resolved". At this point our SLA pauses to await the caller feedback.

I need to add the following, but my Javascript knowledge is very limited:

  1. The Problem to automatically close once all of the related incidents are set to closed.
  2. The problem cannot be set to closed when there are related incidents that have not yet been closed.

The current code I have in place is below (I didnt create it):

if (current.state.changesTo(8)) {

    closeRelatedIncidents(current);

    closeRelatedTasks(current);

}

//

// Close any incidents that are related to the current problem

//

function closeRelatedIncidents(me) {

  var incident = new GlideRecord("incident");

  incident.addQuery("problem_id", "=", me.sys_id);

  incident.query();

  while (incident.next()) {

      if ( incident.state !== 'Closed' || incident.state !== 'Resolved' ){

          var msg = "Incident " + incident.number + ' resolved by problem '+me.number +' and will be closed based on caller response.';

          gs.print(msg);

          incident.state.setValue(8);

          incident.comments = msg;

          incident.update();

      }

  }

}

If there's anoyone who has done what I need to do, how did you do it?!

Thanks i advance.

10 REPLIES 10

guhann
Mega Guru

Tom,



I have just modified the function. Try this out.



function closeRelatedIncidents(me) {  


  var incident = new GlideRecord("incident");  


  incident.addQuery("problem_id", me.sys_id);


incident.addQuery("state","!=",8); //Fetch any incidents with state other than closed.


  incident.query();  


  while (incident.next()) {      


          var msg = "Incident " + incident.number + ' resolved by problem '+me.number +' and will be closed based on caller response.';  


          gs.print(msg);  


          incident.state.setValue(8);  


          incident.comments = msg;


          incident.update();    


  }  


}


tomcamish
Kilo Contributor

Hi Guhan,



Thanks for your reply.



I've tried the script you provided and it seems to do exactly what my existing script does, in that when I set the Problem state to "Resolved", the Incidents are resolved as required.



What I need it to do is to prevent me from setting the Problem state to Closed when the Incidents are still open, and if i set the Incidents to Closed, the problem state needs to change to closed.



Thanks,


Apologies, I didn't get ur requirement clear before. Okay now you gotta do like below,



1) For preventing problem closure if any related INCs are active


if (current.state.changesTo(8)) {  


      if (!relatedIncidentsClosed(current)) {


                gs.addErrorMessage('Related incidents are not closed yet. Please close them before closing the Problem ticket.');


                current.setAbortAction(true);


      }


}



function closeRelatedIncidents(me) {


  var incident = new GlideRecord("incident");


  incident.addQuery("problem_id", me.sys_id);


  incident.addQuery("state","!=",8); //Fetch any incidents with state other than closed.


  incident.query();


  return incident.next();


}



2) For closing the problem after all the relevant INCs are closed



Write an after update BR on incident table with below condition and script



Condition: current.state.changesTo(8)


Script:



  var incident = new GlideRecord("incident");


  incident.addQuery("problem_id", current.problem_id);


  incident.addQuery("sys_id", "!=",current.sys_id);


  incident.addQuery("state","!=",8); //Fetch any incidents with state other than closed.


  incident.query();


  if (!incident.next()) {


          var problem = current.problem_id.getRefRecord();


          problem.state = 8; //State closed


          problem.comments = 'Problem auto closed as all the related incidents are closed by caller.';


  }



Try this and let me know if any questions.


tomcamish
Kilo Contributor

These would be Business Rules?