|
| 1 | +(function runMailScript(current, email, email_action, event) { |
| 2 | + var gr = new GlideRecord('sn_customerservice_case'); // Replace with case table name) |
| 3 | + var caseLink = '<a href="' + current.getLink() + '" style="font-weight: bold;">' + current.number + '</a>'; // Creates a clickable link to the case record |
| 4 | + var subject = 'Added to case ' + current.number; // Sets the subject with the current case number |
| 5 | + email.setSubject(subject); |
| 6 | + |
| 7 | + // Querying for the case record |
| 8 | + gr.addQuery('sys_id', current.sys_id); |
| 9 | + gr.query(); |
| 10 | + |
| 11 | + // Get the reference to the user |
| 12 | + var firstName = event.parm2; // Retrieve the first name from the event |
| 13 | + |
| 14 | + // Ensure proper greeting format |
| 15 | +firstName = firstName ? firstName : "Team"; // Default to "Team" if no first name |
| 16 | + |
| 17 | + // Top Banner |
| 18 | + var banner = |
| 19 | + '<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;">' + |
| 20 | + '<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt;">' + |
| 21 | + // Creates a clickable logo. Insert a hover title and destination URL |
| 22 | + '<a title="Hover title" href="https://www.designation.com">' + |
| 23 | + '<img src="imagename.png" width="168" height="56" />' + // Image name from System UI>Images table |
| 24 | + '</a>' + |
| 25 | + '</span>' + |
| 26 | + '</div>'; |
| 27 | + |
| 28 | + var emailBody = banner; |
| 29 | + |
| 30 | + // Body font style |
| 31 | + emailBody += |
| 32 | + '<div style="font-family: Arial, sans-serif; font-size: 16px; color: black;">' + |
| 33 | + '<p>Hello ' + firstName + ',<br><br>' + |
| 34 | + 'You have been added to case ' + caseLink + '\'s watch list. Click the link to view the case details.</p>' + |
| 35 | + |
| 36 | + '<table style="width: 100%;">'; |
| 37 | + |
| 38 | + if (gr.next()) { |
| 39 | + // Display description and location (replace with field names you want to display) |
| 40 | + emailBody += '<tr>'; |
| 41 | + emailBody += '<td style="width: 120px; padding-left: 20px; padding-right: 0px; font-weight: bold; text-align: left;">Description:</td>'; // Replace "Description" |
| 42 | + emailBody += '<td style="padding-left: 0px;">' + gr.description + '</td>'; // Replace "description" |
| 43 | + emailBody += '</tr>'; |
| 44 | + |
| 45 | + emailBody += '<tr>'; |
| 46 | + emailBody += '<td style="width: 120px; padding-left: 20px; padding-right: 0px; font-weight: bold; text-align: left;">Location:</td>'; // Replace "Location" |
| 47 | + emailBody += '<td style="padding-left: 0px;">' + gr.location.getDisplayValue() + '</td>'; // Replace "location" |
| 48 | + emailBody += '</tr>'; |
| 49 | + |
| 50 | + // Query for attachments related to this case |
| 51 | + var attachmentGr = new GlideRecord('sys_attachment'); |
| 52 | + attachmentGr.addQuery('table_sys_id', current.sys_id); |
| 53 | + attachmentGr.query(); |
| 54 | + |
| 55 | + // Insert attachments from the case |
| 56 | + if (attachmentGr.hasNext()) { |
| 57 | + emailBody += '<tr>'; |
| 58 | + emailBody += '<td style="width: 120px; padding-left: 20px; padding-right: 0px; font-weight: bold; text-align: top; vertical-align: top;">Images:</td>'; |
| 59 | + emailBody += '<td style="padding-left: 0px;">'; |
| 60 | + |
| 61 | + while (attachmentGr.next()) { |
| 62 | + var attachmentLink = gs.getProperty('glide.servlet.uri') + 'sys_attachment.do?sys_id=' + attachmentGr.sys_id; |
| 63 | + var fileName = attachmentGr.file_name; |
| 64 | + |
| 65 | + // Check if the file is an image |
| 66 | + if (attachmentGr.content_type.startsWith('image/')) { |
| 67 | + emailBody += '<p style="margin-bottom: 10px;"><img src="' + attachmentLink + '" alt="' + fileName + '" style="max-width: 400px;"></p>'; |
| 68 | + } else { |
| 69 | + emailBody += '<p><a href="' + attachmentLink + '" target="_blank">' + fileName + '</a></p>'; |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + emailBody += '</td>'; |
| 74 | + emailBody += '</tr>'; |
| 75 | + |
| 76 | + // If there are no attachments |
| 77 | + } else { |
| 78 | + emailBody += '<tr><td colspan="2" style="padding-left: 20px;"><b>No attachments found for this case.</b></td></tr>'; |
| 79 | + } |
| 80 | + |
| 81 | + // If there are no details |
| 82 | + } else { |
| 83 | + emailBody += '<tr><td colspan="2" style="padding-left: 10px;">No matching case details found.</td></tr>'; |
| 84 | + } |
| 85 | + |
| 86 | + // Close the table |
| 87 | + emailBody += '</table>'; |
| 88 | + |
| 89 | + // Closing the email body |
| 90 | + emailBody += '<p>Best regards,<br>(name)</p>'; // Replace name |
| 91 | + emailBody += '</div>'; |
| 92 | + |
| 93 | + // Bottom banner |
| 94 | + var bottombanner = |
| 95 | + '<div class="bottom-banner" style="' + |
| 96 | + 'background-color: #000000;' + |
| 97 | + 'height: 10px;' + |
| 98 | + 'border-top: 4px solid gold;' + |
| 99 | + 'border-radius: 5px;' + |
| 100 | + 'margin-top: 20px;' + |
| 101 | + '"></div>'; |
| 102 | + |
| 103 | + // Add the bottom banner to the email body |
| 104 | + emailBody += bottombanner; |
| 105 | + |
| 106 | + // Print the email body |
| 107 | + template.print(emailBody); |
| 108 | + |
| 109 | +})(current, email, email_action, event); |
| 110 | + |
0 commit comments