Problem Closure and Related Incidents
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2015 06:00 AM
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:
- The Problem to automatically close once all of the related incidents are set to closed.
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2015 06:10 AM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2015 07:36 AM
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2015 07:57 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2015 07:59 AM
These would be Business Rules?