-
Notifications
You must be signed in to change notification settings - Fork 678
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
TechnologistTim
wants to merge
14
commits into
ServiceNowDevProgram:main
from
TechnologistTim:Email-business-rule/mail-script
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0c26675
Create Business Rule
TechnologistTim 5e33146
Merge branch 'ServiceNowDevProgram:main' into Email-business-rule/mai…
TechnologistTim 29778e8
Merge branch 'ServiceNowDevProgram:main' into Email-business-rule/mai…
TechnologistTim 55657c4
Create Business rule to call an event
TechnologistTim 27c22ba
readMe
TechnologistTim b0179cd
Create mail:script
TechnologistTim 61e77b7
Readme
TechnologistTim 49f250a
Create Mail:script
TechnologistTim e2f5d03
Update Mail:script
TechnologistTim 5b27c86
Delete Notifications/mail:script
TechnologistTim e57ee84
Delete Notifications/Business rule to call an event
TechnologistTim 57befdc
Create Old vs New list Business Rule
TechnologistTim d9e11c0
Delete Notifications/readMe
TechnologistTim 67dd204
Create Readme
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,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); |
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. Invalid file name/type. Will fail to clone to local on Windows OSes |
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,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); | ||
|
||
})(); |
17 changes: 17 additions & 0 deletions
17
Notifications/Added to field notification/Old vs New list Business Rule
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,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); |
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,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. |
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.
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.
Invalid file structure location, see CONTRIBUTING.md