- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2019 01:12 PM
Hi all,
I have a requirement to email incident owner when a problem is closed. The problem can have a single or multiple incidents attached to a single problem. My question is how to email the incident owner or multiple incidents owner attached to the problem when a problem is closed?
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2019 10:05 PM
I tried below code and it worked.
1. Create an event using event registry
2. Create a notification on problem table to trigger when event is fired and create notification body and subject as per your requirements. Also see who will receive section snippet below for recipients
3. Create an on After business rule on problem table with condition to trigger when state of the problem changes to closed/resolved
(function executeRule(current, previous /*null when async*/) {
var incidentOwners = [];
var incidentAssignee = [];
var incidentGR = new GlideRecord("incident");
incidentGR.addQuery("problem_id", current.sys_id);
incidentGR.addActiveQuery();
//Can add additional conditions like below based on requirements;
/*
incidentGR.addQuery("state", IncidentState.AWAITING_PROBLEM);
incidentGR.addQuery("hold_reason", IncidentReason.AWAITING_PROBLEM);*/
incidentGR.query();
while (incidentGR.next()) {
incidentAssignee.push(incidentGR.getValue('assigned_to'));
incidentOwners.push(incidentGR.getValue('caller_id')); //Modified Incident Owner field name accordingly
}
if (incidentOwners.length >0 || incidentAssignee.length >0)
gs.eventQueue('incident.problem_close', current, incidentAssignee.toString(), incidentOwners.toString(), '');
})(current, previous);
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2019 01:39 PM
Adm,
Create an after update BR on the Problem table as noted below:
Condition: current.isValidRecord()
if (current.problem_state.changesTo(4)) {
notifyRelatedIncidentOwners(current);
}
//
// Notify all related Incident Owners
//
function notifyRelatedIncidentOwners(me) {
var incident = new GlideRecord("incident");
incident.addQuery("problem_id", "=", me.sys_id);
incident.query();
while (incident.next()) {
if ( incident.active == true ){
var msg = "Incident " + incident.number + ' has been resolved by problem '+notif.number +' .';
gs.print(msg);
incident.comments = msg;
incident.update();
}
}
}
Thanks,
Derrick Johnson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2019 02:51 PM
Created an After BR.
I checked my email logs and didn't find anything. The email is suppose to go to the incident assignee (assigned_to field) and I didn't find any email in the logs.
I have couple questions.
Where is email to assignee being done in the code?
Can you also explain where are you getting "notif" in notif.number from?
Appreciate your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2019 10:05 PM
I tried below code and it worked.
1. Create an event using event registry
2. Create a notification on problem table to trigger when event is fired and create notification body and subject as per your requirements. Also see who will receive section snippet below for recipients
3. Create an on After business rule on problem table with condition to trigger when state of the problem changes to closed/resolved
(function executeRule(current, previous /*null when async*/) {
var incidentOwners = [];
var incidentAssignee = [];
var incidentGR = new GlideRecord("incident");
incidentGR.addQuery("problem_id", current.sys_id);
incidentGR.addActiveQuery();
//Can add additional conditions like below based on requirements;
/*
incidentGR.addQuery("state", IncidentState.AWAITING_PROBLEM);
incidentGR.addQuery("hold_reason", IncidentReason.AWAITING_PROBLEM);*/
incidentGR.query();
while (incidentGR.next()) {
incidentAssignee.push(incidentGR.getValue('assigned_to'));
incidentOwners.push(incidentGR.getValue('caller_id')); //Modified Incident Owner field name accordingly
}
if (incidentOwners.length >0 || incidentAssignee.length >0)
gs.eventQueue('incident.problem_close', current, incidentAssignee.toString(), incidentOwners.toString(), '');
})(current, previous);
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2019 01:44 PM
Thank you so much. That worked.