Attachment in email notification

rajeevlochan82
Mega Guru

How can we embed a Document in a email notification. I just find embedding a link to a document in Servicenow but could not find attaching a file to a notification. I am not looking to send atachments of a record to email notification but sending a standard document (same document) in a specific type of notifications

1 ACCEPTED SOLUTION

rajeevlochan82
Mega Guru

Hi Mohammed,



The only way you can do this is by attaching the document with the specific record and then selecting option "Include attachments" with notification.


In my case as I needed to send a attachment with approval record.


#First I uploaded the document which I have to sent with each approval in Knowledge Base.


#Then I created Approval record using script and copied the knowledge document to the newly created approval record.


# Then used a event queue to sent approval notification , once attachment is copied. (I do made sure to select option "include attachments" in email notification prioperties.)





var grRec = new GlideRecord('sysapproval_approver');


grRec.initialize();


grRec.approver = current.variables.manager;


grRec.source_table   = 'sc_req_item';


grRec.document_id = current.sys_id;


grRec.sysapproval = current.sys_id;


grRec.document_table = 'sc_req_item';


grRec.state = 'requested';


grRec.insert();



GlideSysAttachment.copy('kb_knowledge', '92608c264fa0cb80f0cfe0024210c764', 'sysapproval_approver', grRec.sys_id);



gs.eventQueue('test.approval.notification',grRec,current.variables.manager);


View solution in original post

8 REPLIES 8

darius_koohmare
ServiceNow Employee
ServiceNow Employee

Setting the 'Include attachments' field on the notification to true will include all attachments from the current record that is triggering the notification. So if you attach an attachment to a record, and theres a notification on that record with 'include attachments' set to true, the attachments will also send.


I am not looking for attachments from a specific record. I already have this setting in my notification. So consider the scenario. I have a employee checklist document and I want to sent this same document with every new Hire request. So this document is not associated with any particular record......


dravvyramlochun
ServiceNow Employee
ServiceNow Employee

Hello Rajeev,



Create the following script


Name: Include Attachments in an Email Notification


Type:


Table:


Description: Include this in the email notification or template to include attachments. Replace INSTANCE with your instance name.


Parameters:


Script:


   printattachments();   
function printattachments()
{ var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',current.sys_id);
gr.query();

while
(gr.next())
{ template.print('Attachment: <a href="http://'+gs.getProperty("instance_name")+'.service-now.com/sys_attachment.do?sys_id=' + gr.sys_id + '">' + gr.file_name + '</a>'); } }

Have a look at these articles:


http://wiki.servicenow.com/index.php?title=Include_Attachments_in_an_Email_Notification#gsc.tab=0


Document attachments on an email notification


Hi Rajeev I just ran into the same issue.   I believe the solution Dravvy has described above is the only way to do this - you must create a mail script using the code above which creates a link to the attachment in Service Now (just attach the file to the Notification to get it into the attachments table and then call the mail script in your Notification)