Attachments in notifications

YenGar
Mega Sage

Hello all,

I am working on a vendor project and having an issue with attachments in notifications. I have two PDF attachments that I am trying to include in a notification that goes out to an external customer (outside of our ServiceNow). I have written the email script and added it to the notification body to include the attachment and it works. The problem that I am having is that in order to open the document, the user must be signed in to ServiceNow, otherwise, they are not able to open the document. Has anyone been able to send notifications from servicenow with attachments to an external user that does not require to log in to the instance? I have attached some screenshots for you to see. Please let me know of any ideas.

Email script:

email script.PNG

part of the notification (i have checked the "Include attachments" box but that didn't make a difference.

notification email.PNG

email the user should receive:

actual email.PNG

when clicking on the links, this is what the user gets:

email.PNG

Please let me know of what I can do to fix this issue.

Thank you!

Yeny Garcia

1 ACCEPTED SOLUTION

YenGar
Mega Sage

Hello all,



I was able to get this working using a business rule to attach the documents to the email. I hope that this helps other users also who are stuck on the same issue.



First, attach the documents to the notification that will be triggered. Then create a business rule on the sys_email table.


BR


When: Before, Insert


Condition: current.mailbox.getDisplayName() != "Sent" && current.subject == "NEW APPROVED VENDOR EMAIL"


Script:


var strTemp = '';


var attachment = new GlideRecord('sysevent_email_action');


attachment.addQuery('name', 'CONTAINS', 'email to vendor');


attachment.query();


while (attachment.next()) {


  strTemp = attachment.sys_id.toString();


  //copy the found attachment to the new data source above.


      GlideSysAttachment.copy('sysevent_email_action', strTemp, 'sys_email', current.sys_id);


  gs.log('Copy of attcahments for ' + strTemp);


}



This got me to attach the actual document to the email vs the link. Hope this helps. If you have a better way of doing this though, please let me know!



Thank you,


Yeny


View solution in original post

12 REPLIES 12

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Instead of using the package call you need to use GlideSysAttachment.copy() as package calls are no longer allowed.


Hi Brad,



Thank you for that information. I changed the BR to say GlideSysAttachment.copy() instead of what I had... I tried it again but it still not attaching the documents... I have the BR as Before on Insert... should I change that?



br2.PNG


I did like the look of this Harish but unfortunately it doesn't work as the current sys_id in this line:



GlideSysAttachment.copy (gr.table_name, gr.sys_id, 'sys_email', current.sys_id);



Doesn't work because it's of the source record and not the sys_email record. It seems doing it in the Notification (which I would prefer) you can't get the sys_email sys_id and doing it in the Business Rule you can't get the sysevent_email_action sys_id without doing a GlideRecord.



But at least it is possible.


Kalaiarasan Pus
Giga Sage

how about using this field on the notification 'Include attachments'



http://wiki.servicenow.com/index.php?title=Email_Notifications#Advanced_View_Fields


Hi Kalairasan,



I believe the field 'include attachments' will pull the attachments from the source record (like an incident) but I need them to be pulled from the notification record in the notification table... not sure how to do it... any ideas?



Thank you,


Yeny Garcia