Creating a fully automated email notification for Incident tickets.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
Create a fully automated email notification for Incident tickets. However despite having the First Strike, Second Strike and Third Striked all setup. The email is email is is still not showing. Below is my script for the Business Rule
(function executeRule(current, previous) {
// Only run for Service Desk incidents
if (current.assignment_group.getDisplayValue() != 'Service Desk') {
return;
}
// Only run for Awaiting Customer state
// Your Awaiting Customer value is 109
if (current.state.toString() != '109') {
return;
}
var now = new GlideDateTime();
var attempts = current.u_contact_attempts.toString();
// =========================
// FIRST STRIKE
// Trigger:
// Contact Attempts = 0
// =========================
if (attempts == '0') {
current.u_contact_attempts = '1';
current.u_last_contact_date = now;
current.u_next_contact_date = addBusinessDays(now, 5);
gs.eventQueue(
'incident.first.strike',
current,
'',
''
);
gs.addInfoMessage('First Strike executed. Contact Attempts changed to 1.');
return;
}
// =========================
// SECOND STRIKE
// Trigger:
// Contact Attempts = 1
// Next Contact Date changed to today/past
// =========================
if (attempts == '1') {
if (current.u_next_contact_date.changes() &&
isNextContactDue(current.u_next_contact_date, now)) {
current.u_contact_attempts = '2';
current.u_last_contact_date = now;
current.u_next_contact_date = addBusinessDays(now, 5);
gs.eventQueue(
'incident.second.strike',
current,
'',
''
);
gs.addInfoMessage('Second Strike executed. Contact Attempts changed to 2.');
}
return;
}
// =========================
// THIRD STRIKE / FINAL
// Trigger:
// Contact Attempts = 2
// Next Contact Date changed to today/past
// =========================
if (attempts == '2') {
if (current.u_next_contact_date.changes() &&
isNextContactDue(current.u_next_contact_date, now)) {
current.u_contact_attempts = '3';
current.u_last_contact_date = now;
current.u_next_contact_date = '';
// Resolved state value
current.state = '6';
// Optional resolution fields
current.close_code = 'Solved (Work Around)';
current.close_notes = 'Resolved after third customer contact attempt.';
gs.eventQueue(
'incident.third.strike',
current,
'',
''
);
gs.addInfoMessage('Third Strike executed. Incident resolved.');
}
return;
}
// =========================================
// Function: check if Next Contact Date is today or past
// =========================================
function isNextContactDue(nextContactDate, today) {
if (nextContactDate.nil()) {
return false;
}
var nextDate = new GlideDateTime(nextContactDate);
if (nextDate.getNumericValue() <= today.getNumericValue()) {
return true;
}
return false;
}
// =========================================
// Function: add 5 business days
// Skips Saturday and Sunday
// =========================================
function addBusinessDays(startDate, daysToAdd) {
var newDate = new GlideDateTime(startDate);
var addedDays = 0;
while (addedDays < daysToAdd) {
newDate.addDaysLocalTime(1);
var dayOfWeek = newDate.getDayOfWeekLocalTime();
// 1 = Monday
// 2 = Tuesday
// 3 = Wednesday
// 4 = Thursday
// 5 = Friday
// 6 = Saturday
// 7 = Sunday
if (dayOfWeek != 6 && dayOfWeek != 7) {
addedDays++;
}
}
return newDate;
}
})(current, previous);
0 REPLIES 0