From 9f36b4511f02038c529cf3449c078a3afa4b5db1 Mon Sep 17 00:00:00 2001 From: Tim Dingle Date: Thu, 31 Oct 2024 23:01:00 -0500 Subject: [PATCH 1/5] Create content --- Mail Scripts/Added a case/content | 1 + 1 file changed, 1 insertion(+) create mode 100644 Mail Scripts/Added a case/content diff --git a/Mail Scripts/Added a case/content b/Mail Scripts/Added a case/content new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/Mail Scripts/Added a case/content @@ -0,0 +1 @@ + From fb1214d1847d031cad60ffb6601965d76ec56d7f Mon Sep 17 00:00:00 2001 From: Tim Dingle Date: Thu, 31 Oct 2024 23:26:02 -0500 Subject: [PATCH 2/5] Create content --- Mail Scripts/Case details/content | 1 + 1 file changed, 1 insertion(+) create mode 100644 Mail Scripts/Case details/content diff --git a/Mail Scripts/Case details/content b/Mail Scripts/Case details/content new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/Mail Scripts/Case details/content @@ -0,0 +1 @@ + From 65f0bdce1ac3d16057296f3bbc4ebf5c533f116d Mon Sep 17 00:00:00 2001 From: Tim Dingle Date: Thu, 31 Oct 2024 23:26:21 -0500 Subject: [PATCH 3/5] Add files via upload --- .../Case details/Case details notification.js | 110 ++++++++++++++++++ Mail Scripts/Case details/Readme.md | 9 ++ 2 files changed, 119 insertions(+) create mode 100644 Mail Scripts/Case details/Case details notification.js create mode 100644 Mail Scripts/Case details/Readme.md diff --git a/Mail Scripts/Case details/Case details notification.js b/Mail Scripts/Case details/Case details notification.js new file mode 100644 index 0000000000..611ba45a79 --- /dev/null +++ b/Mail Scripts/Case details/Case details notification.js @@ -0,0 +1,110 @@ +(function runMailScript(current, email, email_action, event) { + var gr = new GlideRecord('sn_customerservice_case'); // Replace with case table name) + var caseLink = '' + current.number + ''; // Creates a clickable link to the case record + var subject = 'Added to case ' + current.number; // Sets the subject with the current case number + email.setSubject(subject); + + // Querying for the case record + gr.addQuery('sys_id', current.sys_id); + 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 = + ''; + + var emailBody = banner; + + // Body font style + emailBody += + '
' + + '

Hello ' + firstName + ',

' + + 'You have been added to case ' + caseLink + '\'s watch list. Click the link to view the case details.

' + + + ''; + + if (gr.next()) { + // Display description and location (replace with field names you want to display) + emailBody += ''; + emailBody += ''; // Replace "Description" + emailBody += ''; // Replace "description" + emailBody += ''; + + emailBody += ''; + emailBody += ''; // Replace "Location" + emailBody += ''; // Replace "location" + emailBody += ''; + + // 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 += ''; + emailBody += ''; + emailBody += ''; + emailBody += ''; + + // If there are no attachments + } else { + emailBody += ''; + } + + // If there are no details + } else { + emailBody += ''; + } + + // Close the table + emailBody += '
Description:' + gr.description + '
Location:' + gr.location.getDisplayValue() + '
Images:'; + + 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 += '

' + fileName + '

'; + } else { + emailBody += '

' + fileName + '

'; + } + } + + emailBody += '
No attachments found for this case.
No matching case details found.
'; + + // Closing the email body + emailBody += '

Best regards,
(name)

'; // Replace name + emailBody += '
'; + + // Bottom banner + var bottombanner = + '
'; + + // Add the bottom banner to the email body + emailBody += bottombanner; + + // Print the email body + template.print(emailBody); + +})(current, email, email_action, event); + diff --git a/Mail Scripts/Case details/Readme.md b/Mail Scripts/Case details/Readme.md new file mode 100644 index 0000000000..1b08087d07 --- /dev/null +++ b/Mail Scripts/Case details/Readme.md @@ -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) \ No newline at end of file From 2ef2531adc2ef11bfd074e92d2e50e1e6a67f02c Mon Sep 17 00:00:00 2001 From: Tim Dingle Date: Thu, 31 Oct 2024 23:26:49 -0500 Subject: [PATCH 4/5] Delete Mail Scripts/Case details/content --- Mail Scripts/Case details/content | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Mail Scripts/Case details/content diff --git a/Mail Scripts/Case details/content b/Mail Scripts/Case details/content deleted file mode 100644 index 8b13789179..0000000000 --- a/Mail Scripts/Case details/content +++ /dev/null @@ -1 +0,0 @@ - From b30edbfe9dbf236772a0ba06023f9ad526b4a478 Mon Sep 17 00:00:00 2001 From: Tim Dingle Date: Fri, 1 Nov 2024 10:22:15 -0500 Subject: [PATCH 5/5] Update Case details notification.js Revised the code to simplify the use of current, removed the extra glide record as well as subject (since it can be set directly in the notification), and converted to getValues. --- .../Case details/Case details notification.js | 111 +++++++----------- 1 file changed, 41 insertions(+), 70 deletions(-) diff --git a/Mail Scripts/Case details/Case details notification.js b/Mail Scripts/Case details/Case details notification.js index 611ba45a79..24b3f69c30 100644 --- a/Mail Scripts/Case details/Case details notification.js +++ b/Mail Scripts/Case details/Case details notification.js @@ -1,110 +1,81 @@ (function runMailScript(current, email, email_action, event) { - var gr = new GlideRecord('sn_customerservice_case'); // Replace with case table name) - var caseLink = '' + current.number + ''; // Creates a clickable link to the case record - var subject = 'Added to case ' + current.number; // Sets the subject with the current case number - email.setSubject(subject); + // Store frequently used `current` values in variables to avoid multiple calls + var caseSysId = current.getValue('sys_id'); + var caseNumber = current.getValue('number'); + var caseLink = '' + caseNumber + ''; - // Querying for the case record - gr.addQuery('sys_id', current.sys_id); - gr.query(); + // Retrieve the first name from the event parameter, defaulting to "Team" if missing + var firstName = event.parm2 || "Team"; - // 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 = + // Top banner HTML + var banner = ''; - var emailBody = banner; - - // Body font style - emailBody += + // Initialize email body with banner + var emailBody = banner + '
' + - '

Hello ' + firstName + ',

' + - 'You have been added to case ' + caseLink + '\'s watch list. Click the link to view the case details.

' + - + '

Hello ' + firstName + ',

' + + 'You have been added to case ' + caseLink + '\'s watch list. Click the link to view the case details.

' + ''; - if (gr.next()) { - // Display description and location (replace with field names you want to display) - emailBody += ''; - emailBody += ''; // Replace "Description" - emailBody += ''; // Replace "description" - emailBody += ''; + // Case record processing + var gr = new GlideRecord('sn_customerservice_case'); + if (gr.get(caseSysId)) { + // Using getValue() for fields to ensure direct string handling + emailBody += ''; + emailBody += ''; - emailBody += ''; - emailBody += ''; // Replace "Location" - emailBody += ''; // Replace "location" - emailBody += ''; + emailBody += ''; + emailBody += ''; - // Query for attachments related to this case + // Retrieve attachments associated with the case var attachmentGr = new GlideRecord('sys_attachment'); - attachmentGr.addQuery('table_sys_id', current.sys_id); + attachmentGr.addQuery('table_sys_id', caseSysId); attachmentGr.query(); - // Insert attachments from the case + // Attachments section if (attachmentGr.hasNext()) { - emailBody += ''; - emailBody += ''; - emailBody += ''; + emailBody += ''; - emailBody += ''; - - // If there are no attachments + emailBody += ''; } else { emailBody += ''; } - - // If there are no details } else { emailBody += ''; } - // Close the table + // Closing the table and email body emailBody += '
Description:' + gr.description + '
Description:' + gr.getValue('description') + '
Location:' + gr.location.getDisplayValue() + '
Location:' + gr.getDisplayValue('location') + '
Images:'; - + emailBody += '
Images:'; + while (attachmentGr.next()) { - var attachmentLink = gs.getProperty('glide.servlet.uri') + 'sys_attachment.do?sys_id=' + attachmentGr.sys_id; - var fileName = attachmentGr.file_name; + var attachmentLink = gs.getProperty('glide.servlet.uri') + 'sys_attachment.do?sys_id=' + attachmentGr.getValue('sys_id'); + var fileName = attachmentGr.getValue('file_name'); - // Check if the file is an image - if (attachmentGr.content_type.startsWith('image/')) { - emailBody += '

' + fileName + '

'; + // Display image if applicable, otherwise show a link + if (attachmentGr.getValue('content_type').startsWith('image/')) { + emailBody += '

' + fileName + '

'; } else { emailBody += '

' + fileName + '

'; } } - - emailBody += '
No attachments found for this case.
No matching case details found.
'; - - // Closing the email body - emailBody += '

Best regards,
(name)

'; // Replace name + emailBody += '

Best regards,
(name)

'; emailBody += '
'; - // Bottom banner - var bottombanner = - '
'; + // Bottom Banner HTML + var bottombanner = + '
'; - // Add the bottom banner to the email body + // Append bottom banner to the email body emailBody += bottombanner; - // Print the email body + // Output the email body template.print(emailBody); })(current, email, email_action, event); -