Include attachments on e-mail notification

Brent Cox
Mega Guru

I have set up a quick notification, so that when a certain assignment group is assigned, it sends a notification to a 3rd party support system with the ticket information. This is working correctly. Now, I need to make sure that attachments on ticket creation AND attachments left as a work comment on the ticket both get included on this notification. As of right now, when I set an attachment on the INC, it does not trigger a notification. How can I set this up? 

3 REPLIES 3

Dnyaneshwaree
Mega Sage

Hello @Brent Cox ,

Please post the logic that you have used for the same like notification, script, etc.

Thank you!!

Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!

Dnyaneshwaree Satpute
Tera Guru

Email Notification: table, incident. 
Send When: record inserted or updated (I want it to include both when the ticket is created and when comments are made on the incident record). 
Conditions: Assignment group is 'support group' 
Who Will Receive: '3rd party service desk e-mail' 

This is all I have set up currently. This is a quick and dirty set up for a temporary resolution. This is not a true interface of any kind, but just a way for them to get notifications when tickets on our side are created or commented on. However, included in this notification, I need it to include attachments. I have now checked "include attachments" in the notification, which I am hoping will take care of attachments added when creating the ticket. The main issue might be if they add attachments later. Those don't seem to be generating e-mails like a regular work comment is. 

 

blaze1
Tera Contributor

Sorry for the late response:

To ensure that attachments, both added when the ticket is created and added later as work comments, are included in the notification, follow these steps:

1. **Set up the notification for both incident creation and work comment updates**:
- Since you are already triggering the notification for "record inserted or updated," the important thing here is to make sure that both the incident record and work comment attachments are included.

2. **Ensure "Include Attachments" is checked**:
In the **Email Notification** settings, make sure the "Include Attachments" box is checked. This ensures that attachments from the incident are sent with the notification. However, this alone won't cover work comment attachments.

3. **Use a script to include work comment attachments**:
You will need to modify the notification or create a **Scripted Notification** to fetch attachments related to **work comments**. Here’s an example of how to include both types of attachments (on the incident and work comments):

```javascript
(function sendAttachments() {
var attachments = [];
// Get attachments on the incident
var incidentAttachments = new GlideRecord('sys_attachment');
incidentAttachments.addQuery('table_name', 'incident');
incidentAttachments.addQuery('table_sys_id', current.sys_id);
incidentAttachments.query();
while (incidentAttachments.next()) {
attachments.push(incidentAttachments.sys_id + '');
}

// Get attachments from work comments
var workCommentAttachments = new GlideRecord('sys_attachment');
workCommentAttachments.addQuery('table_name', 'incident_comment');
workCommentAttachments.addQuery('table_sys_id', current.sys_id);
workCommentAttachments.query();
while (workCommentAttachments.next()) {
attachments.push(workCommentAttachments.sys_id + '');
}

// Attachments are added to the notification email
current.email.addAttachment(attachments);
})();
```

4. **Add the Script to the Email Notification**:
- Go to the **Email Notification** setup and add this script under the **Advanced Options** in the **Script** section.
- This script will fetch attachments from both the incident and the work comments, ensuring they’re included in the notification.

5. **Testing**:
- Test the notification by adding attachments both when creating the incident and adding work comments. Check if the notification is correctly sending both.

### Key Points:
- **Attachments from incident records**: You’ve already checked "include attachments."
- **Attachments from work comments**: You’ll need to script it to fetch these and attach them in the email.

This solution will ensure that any attachments added to the incident (either initially or as work comments) are included in the notification sent to the 3rd party support system.

Blaze Llanos, USMC, MISM
ServiceNow Engineer
Solutions: IT | ServiceNow Expertise Transforming Challenges into Solutions
LinkedIn: https://www.linkedin.com/in/blazellanos/