Skip to content

Email business rule/mail script for a case #1579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
19 changes: 19 additions & 0 deletions Business Rules/Business Rule
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid file structure location, see CONTRIBUTING.md

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
A business rule to trigger an event on a notification when someone is added to a list. It also parses a user's first name.

(function executeRule(current, previous /*null when async*/) {

// Assuming you are getting the list of added users from the watchlist
var addedUsers = current.<list field name>.split(',');

// Loop through the added users to trigger the event for each
addedUsers.forEach(function(userID) {
// Get the user record to retrieve first name
var userGr = new GlideRecord('sys_user');
if (userGr.get(userID)) {

// Fire an event for each user with their first name
gs.eventQueue('<event name>’, current, userID, userGr.first_name);
}
});

})(current, previous);
74 changes: 74 additions & 0 deletions Notifications/Added to field notification/Mail:script
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid file name/type. Will fail to clone to local on Windows OSes

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Top Banner
var banner =
'<div class="banner" style="background-color: #000000; color: white; padding-top: 0px; padding-left: 10px; text-align: left; border-bottom: 5px solid gold; border-radius: 5px;">' +
'<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt;">' +
'<a title="<POP UP NAME>" href="<website>">' +
'<img src="<image name in the instance>" width="168" height="56" />' +
'</a>' +
'</span>' +
'</div>';

var emailBody = banner;

emailBody += '<div style="font-family: Arial, sans-serif; font-size: 16px; color: black;">';
emailBody += '<p>Team,<br><br>';
emailBody += 'New attachments have been added to case ' + caseLink + '. Click the link to view the case details.</p>';
emailBody += '<table style="width: 100%;">';

emailBody += '<tr>';
emailBody += '<td style="width: 120px; padding-left: 20px; padding-right: 0px; font-weight: bold; text-align: left;">Description:</td>';
emailBody += '<td style="padding-left: 0px;">' + current.description + '</td></tr>';

emailBody += '<tr>';
emailBody += '<td style="width: 120px; padding-left: 20px; padding-right: 0px; font-weight: bold; text-align: left;">Location:</td>';
emailBody += '<td style="padding-left: 0px;">' + current.location.getDisplayValue() + '</td></tr>';

// Query the attachments
var attachmentGr = new GlideRecord('sys_attachment');
attachmentGr.addQuery('table_sys_id', current.sys_id);
attachmentGr.query();

if (attachmentGr.hasNext()) {
emailBody += '<tr>';
emailBody += '<td style="width: 120px; padding-left: 20px; padding-right: 0px; font-weight: bold; text-align: top; vertical-align: top;">Attachments:</td>';
emailBody += '<td style="padding-left: 0px;">';

while (attachmentGr.next()) {
var attachmentLink = gs.getProperty('glide.servlet.uri') + 'sys_attachment.do?sys_id=' + attachmentGr.sys_id;
var fileName = attachmentGr.file_name;

// Check if the file is an image
if (attachmentGr.content_type.startsWith('image/')) {
emailBody += '<p style="margin-bottom: 10px;"><img src="' + attachmentLink + '" alt="' + fileName + '" style="max-width: 400px;"></p>';
} else {
emailBody += '<p><a href="' + attachmentLink + '" target="_blank">' + fileName + '</a></p>';
}
}

emailBody += '</td></tr>';
} else {
emailBody += '<tr><td colspan="2" style="padding-left: 20px;"><b>No attachments found for this case.</b></td></tr>';
}

emailBody += '</table>';
emailBody += '<p>Best regards,<br><NAME></p>';
emailBody += '</div>';

// Bottom banner
var bottombanner =
'<div class="bottom-banner" style="' +
'background-color: #000000;' +
'height: 10px;' +
'border-top: 4px solid gold;' +
'border-radius: 5px;' +
'margin-top: 20px;' +
'"></div>';

// Add the bottom banner to the email body
emailBody += bottombanner;

'</div>';

template.print(emailBody);

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(function executeRule(current, previous /*null when async*/) {

// Assuming you are getting the list of added users from the watchlist
var addedUsers = current.<list field name>.split(',');

// Loop through the added users to trigger the event for each
addedUsers.forEach(function(userID) {
// Get the user record to retrieve first name
var userGr = new GlideRecord('sys_user');
if (userGr.get(userID)) {

// Fire an event for each user with their first name
gs.eventQueue('<event name>’, current, userID, userGr.first_name);
}
});

})(current, previous);
5 changes: 5 additions & 0 deletions Notifications/Added to field notification/Readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This pull contains a business rule and a mail:script.

The business rule compares the old list to a newly saved list then calls an event to trigger a notification whenever someone new is added to a field/list. It will parse the user's first name so the mail script within the notification can address the recipient by first name if desired.

The main:script contains a header banner, body and footer banner. The body is a response and can be used when there is an update to a case. It has a link to the case, description, location and embeds any attachments that are on the case.
Loading