- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 09-23-2021 12:16 AM
Hi Experts,
If you want to send an attachment in notification there are a couple of ways to do it.
I will summarize it in this article.
- All attachments from records.
- Specific attachment
-
- As physical attachment.
- As a link in the record
==========================================================================
1. All attachments from records.
This is the simplest one. If you have attachemnts attached to records and want to send all notifications then it is just a matter of making a check box true.
Go to your desired notification and make the "Include attachments" check box as true.
If your record has an attachment it will be sent over email as a physical attachment.
==========================================================================
2. Specific attachment.
There might be a scenario where the attachment is not attached to the record but you have to send some attachments in the notification. This can be done in 2 ways.
a. Send physical attachment
b. Send attachment download link in the mail.
a. Send physical attachment:
To send a physical attachment we have to create a Business rule to add attachment as physically in the notification.
Create Business Rule on Email table with the following details:
Table: Email [sys_email]
When: Before
Insert: True
Condition: Mailbox is Outlook
AND
Any other condition to match your requirement
Script:
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.get('<your_attachment_sys_id>'); //replace <your_attachment_sys_id> your attachment sys_id
var attContent = new GlideSysAttachment().getContentStream(grAttachment.sys_id);
new GlideSysAttachment().writeContentStream(current, grAttachment.getValue('file_name'), grAttachment.getValue('content_type'), attContent);
Business Rule:
b. Send attachment download link in the mail
This will add a link in your notification to download the attachment.
When a user clicks on that link they will be asked to login to the ServiceNow instance if they are not logged in. Once logged in attachment will be downloaded.
To have a link in the notification we have to create an email script as follow and use it in the notification
Create Email script:
Name: add_attachment_link
Script:
var attachmentSysId = 'a7cb84bf2f1630107f282aa62799b6ae'; // get sys_id your attachment from sys_attachment table
var nameOfAttachment = 'Click here to download'; //Name on link
var link = "<a href = /sys_attachment.do?sys_id=" + attachmentSysId + ">" + nameOfAttachment + "</a>" ;
template.print(link);
Once an email script is created open your notification and call mail script into it
Open the notification and write the below code at bottom of notification "Message HTML"
${mail_script:add_attachment_link}
This will add a link to your notification to download the attachment.
- 11,405 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi VIkram19,
The article was very helpful. I found a few oddities. I have an notification that gets triggered from an inbound email. When I did the initial setup, I checked Include Attachments. Unfortunately all that I got was whatever attachments were part of the inbound email that triggered the notification.
When I set up the business rule, the filter conditions prevented the BR from triggering. When I added subject==xxx to the conditions, that worked. The other thing that I noticed is that mailbox was unpopulated when the before insert BR triggered.
Thanks again for the post.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
For our org, we agreed that sending physical attachments is not feasible, besides the obvious performance issues that can result, the sheer number or size of attachments that accumulate, could fail since email has different limits than ServiceNow would. You should consider only sending a link. Who will want to know who your target audience is (requester, assignee, assignment group, watchlist, incident reporter) and which record it works for (Incident, Request, etc.) However, no matter how you dice it, there will be complexity and performance issues with trying to build this solution because you are touching some pretty large tables and dot walking from the sys_attachment table into the sc_task, sc_req_item, and sc_request table (depending on who is adding an attachment, and which task). The link should be dynamic so that roles-based access is managed, i.e. end users get directed to the portal and ITIL users get directed to the native view records. We are currently looking into this, just for the assignee to get a notification with the link and need to consider the following:
- When attachments are added to REQ, RITM, or SCTASK send an email to all SCTASK assignees.
- When attachments are added by a requester or anyone other than the assignee, send an email with a request link or attachment link, to all the other assignees and not the person who submitted it.
- When multiple attachments are added at one time, restrict the number of emails sent to one, so the assignee doesn't get too many emails.
I'm still trying to decide if this is worth the effort or if it will just introduce more issues. Does anyone know what ITSM best practice is and why ServiceNow hasn't built this feature already?