Skip to content
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

Mail script #1616

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Mail Scripts/Added a case/content
SapphicFire marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a new file? Unfortunately this one needs to go too

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

110 changes: 110 additions & 0 deletions Mail Scripts/Case details/Case details notification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
(function runMailScript(current, email, email_action, event) {
var gr = new GlideRecord('sn_customerservice_case'); // Replace with case table name)
SapphicFire marked this conversation as resolved.
Show resolved Hide resolved
var caseLink = '<a href="' + current.getLink() + '" style="font-weight: bold;">' + current.number + '</a>'; // Creates a clickable link to the case record
var subject = 'Added to case ' + current.number; // Sets the subject with the current case number
SapphicFire marked this conversation as resolved.
Show resolved Hide resolved
email.setSubject(subject);

// Querying for the case record
gr.addQuery('sys_id', current.sys_id);
SapphicFire marked this conversation as resolved.
Show resolved Hide resolved
gr.query();

// Get the reference to the user
var firstName = event.parm2; // Retrieve the first name from the event

// Ensure proper greeting format
firstName = firstName ? firstName : "Team"; // Default to "Team" if no first name

// 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;">' +
// Creates a clickable logo. Insert a hover title and destination URL
'<a title="Hover title" href="https://www.designation.com">' +
'<img src="imagename.png" width="168" height="56" />' + // Image name from System UI>Images table
'</a>' +
'</span>' +
'</div>';

var emailBody = banner;

// Body font style
emailBody +=
'<div style="font-family: Arial, sans-serif; font-size: 16px; color: black;">' +
'<p>Hello ' + firstName + ',<br><br>' +
'You have been added to case ' + caseLink + '\'s watch list. Click the link to view the case details.</p>' +

'<table style="width: 100%;">';

if (gr.next()) {
// Display description and location (replace with field names you want to display)
emailBody += '<tr>';
emailBody += '<td style="width: 120px; padding-left: 20px; padding-right: 0px; font-weight: bold; text-align: left;">Description:</td>'; // Replace "Description"
emailBody += '<td style="padding-left: 0px;">' + gr.description + '</td>'; // Replace "description"
emailBody += '</tr>';

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

// Query for attachments related to this case
var attachmentGr = new GlideRecord('sys_attachment');
attachmentGr.addQuery('table_sys_id', current.sys_id);
attachmentGr.query();

// Insert attachments from the case
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;">Images:</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>';
emailBody += '</tr>';

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

// If there are no details
} else {
emailBody += '<tr><td colspan="2" style="padding-left: 10px;">No matching case details found.</td></tr>';
}

// Close the table
emailBody += '</table>';

// Closing the email body
emailBody += '<p>Best regards,<br>(name)</p>'; // Replace name
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;

// Print the email body
template.print(emailBody);

})(current, email, email_action, event);

9 changes: 9 additions & 0 deletions Mail Scripts/Case details/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Scenario: You are wanting to send a notification that contains: a link to a case, case details such as description and location, and any attachments on the case.

Application: Create a mail script and set the name "Added to case" (replace with desired name). Create a notification, set the name, and table.

When to send:
Choose the conditions.

What it will contain:
"mail_script:added_to_case". // Mail_script:(replace with mail script name)
Loading