SNC - ITIL - Close Related for Incidents

shane_davis
Tera Expert

I am looking at the OOB business rule "SNC - ITIL - Close Related" on the incident table.   My need is that when an incident is closed, it NOT close child Incident Tasks.   I'm not sure how to tell this script to ignore child INC Tasks though.   Any help is appreciated!   Thank you.      

When: After; Insert; Update

Condition: current.isValidRecord()

Script:

//

// Close any child incidents

//

if (current.active.changesTo(false)) {

    closeRelatedTasks(current);

}

1 ACCEPTED SOLUTION

You are correct on the first part.



Deactivate the OOB business rule on incident table and create a copy of it.



Modify its code as given (Code is taken from the related global business rule)



if (current.active.changesTo(false)) {


  closeIncident(current);


}



function closeIncident(me) {


  var incident = new GlideRecord('incident');



  if (incident.isValidField('parent_incident'))


  incident.addQuery('parent_incident', me.sys_id);


  else if(incident.isValidField('parent'))


  incident.addQuery('parent', me.sys_id);


  else


  return;



  incident.addActiveQuery();


  incident.query();


  while (incident.next()) {


  var msg = gs.getMessage("Incident '{0}' closed based on closure of task '{1}'", [incident.number, me.number]);


  gs.print(msg);


  incident.incident_state.setValue(IncidentState.CLOSED);


  incident.active.setValue(false);


  incident.comments = msg;


  var notes = incident.close_notes.getDisplayValue();


  notes = notes + '\n' + msg + '\n\n' + me.close_notes;


  incident.close_notes.setValue(notes);


  incident.close_code.setValue(me.close_code);


  incident.update();


  }


  }



//Sorry script not formatted



Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

9 REPLIES 9

Alikutty,



        If I understand what you are saying, I should not modify the business rule "SNC - ITIL - Close Related" which is on the incident table, but rather copy it and update the script on the copied version.   I would also set the OOB version to inactive.   Is that right?   If so, the help that I need is how to modify the script to ignore Incident Tasks within the "closeRelatedTasks" function.   Sorry, very beginner at scripting here so please overlook if I'm not getting it!   Thank you for your help.



Shane


You are correct on the first part.



Deactivate the OOB business rule on incident table and create a copy of it.



Modify its code as given (Code is taken from the related global business rule)



if (current.active.changesTo(false)) {


  closeIncident(current);


}



function closeIncident(me) {


  var incident = new GlideRecord('incident');



  if (incident.isValidField('parent_incident'))


  incident.addQuery('parent_incident', me.sys_id);


  else if(incident.isValidField('parent'))


  incident.addQuery('parent', me.sys_id);


  else


  return;



  incident.addActiveQuery();


  incident.query();


  while (incident.next()) {


  var msg = gs.getMessage("Incident '{0}' closed based on closure of task '{1}'", [incident.number, me.number]);


  gs.print(msg);


  incident.incident_state.setValue(IncidentState.CLOSED);


  incident.active.setValue(false);


  incident.comments = msg;


  var notes = incident.close_notes.getDisplayValue();


  notes = notes + '\n' + msg + '\n\n' + me.close_notes;


  incident.close_notes.setValue(notes);


  incident.close_code.setValue(me.close_code);


  incident.update();


  }


  }



//Sorry script not formatted



Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


Alikutty,



        I am testing this code in our SandBox instance tonight and will let you know the result Thursday since it takes 24 hours to close the incident after resolution and I am off Wednesday.   Thank you very much for your help!



Shane


Shane,



You can force close an incident for testing it manually, I tried and all child incidents except the incident_task tickets were closed.



Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


Alikutty,



        I understand.   It's always my preference to wait and let the system perform its normal actions when testing.   Your idea would work fine; just something I always do!       I will let you know something soon.



Shane