-
Notifications
You must be signed in to change notification settings - Fork 678
Mail script #1616
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
Open
TechnologistTim
wants to merge
6
commits into
ServiceNowDevProgram:main
Choose a base branch
from
TechnologistTim:Mail-Script
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mail script #1616
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9f36b45
Create content
TechnologistTim fb1214d
Create content
TechnologistTim 65f0bdc
Add files via upload
TechnologistTim 2ef2531
Delete Mail Scripts/Case details/content
TechnologistTim 647c088
Merge branch 'main' into Mail-Script
TechnologistTim b30edbf
Update Case details notification.js
TechnologistTim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a new file? Unfortunately this one needs to go too |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.