-
Notifications
You must be signed in to change notification settings - Fork 658
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
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 all 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
This file contains 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 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,81 @@ | ||
(function runMailScript(current, email, email_action, event) { | ||
// Store frequently used `current` values in variables to avoid multiple calls | ||
var caseSysId = current.getValue('sys_id'); | ||
var caseNumber = current.getValue('number'); | ||
var caseLink = '<a href="' + current.getLink() + '" style="font-weight: bold;">' + caseNumber + '</a>'; | ||
|
||
// Retrieve the first name from the event parameter, defaulting to "Team" if missing | ||
var firstName = event.parm2 || "Team"; | ||
|
||
// Top banner HTML | ||
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="Hover title" href="https://www.designation.com">' + | ||
'<img src="imagename.png" width="168" height="56" />' + | ||
'</a>' + | ||
'</span>' + | ||
'</div>'; | ||
|
||
// Initialize email body with banner | ||
var emailBody = banner + | ||
'<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%;">'; | ||
|
||
// Case record processing | ||
var gr = new GlideRecord('sn_customerservice_case'); | ||
if (gr.get(caseSysId)) { | ||
// Using getValue() for fields to ensure direct string handling | ||
emailBody += '<tr><td style="width: 120px; padding-left: 20px; font-weight: bold; text-align: left;">Description:</td>'; | ||
emailBody += '<td>' + gr.getValue('description') + '</td></tr>'; | ||
|
||
emailBody += '<tr><td style="width: 120px; padding-left: 20px; font-weight: bold; text-align: left;">Location:</td>'; | ||
emailBody += '<td>' + gr.getDisplayValue('location') + '</td></tr>'; | ||
|
||
// Retrieve attachments associated with the case | ||
var attachmentGr = new GlideRecord('sys_attachment'); | ||
attachmentGr.addQuery('table_sys_id', caseSysId); | ||
attachmentGr.query(); | ||
|
||
// Attachments section | ||
if (attachmentGr.hasNext()) { | ||
emailBody += '<tr><td style="width: 120px; padding-left: 20px; font-weight: bold; text-align: top; vertical-align: top;">Images:</td>'; | ||
emailBody += '<td>'; | ||
|
||
while (attachmentGr.next()) { | ||
var attachmentLink = gs.getProperty('glide.servlet.uri') + 'sys_attachment.do?sys_id=' + attachmentGr.getValue('sys_id'); | ||
var fileName = attachmentGr.getValue('file_name'); | ||
|
||
// Display image if applicable, otherwise show a link | ||
if (attachmentGr.getValue('content_type').startsWith('image/')) { | ||
emailBody += '<p><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>'; | ||
} | ||
} else { | ||
emailBody += '<tr><td colspan="2" style="padding-left: 10px;">No matching case details found.</td></tr>'; | ||
} | ||
|
||
// Closing the table and email body | ||
emailBody += '</table>'; | ||
emailBody += '<p>Best regards,<br>(name)</p>'; | ||
emailBody += '</div>'; | ||
|
||
// Bottom Banner HTML | ||
var bottombanner = | ||
'<div class="bottom-banner" style="background-color: #000000; height: 10px; border-top: 4px solid gold; border-radius: 5px; margin-top: 20px;"></div>'; | ||
|
||
// Append bottom banner to the email body | ||
emailBody += bottombanner; | ||
|
||
// Output the email body | ||
template.print(emailBody); | ||
|
||
})(current, email, email_action, event); |
This file contains 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) |
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.
There was a problem hiding this comment.
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