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

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


Yeny,



I've tried this script, modified the subject condition to match my email subject, and modified the attachment.addQuery line to find a contain on my attachment name (I assume that is what this does), is there anything else I need to be mindful of changing to get this Business Role working for my specific email, and my attachment on the email notification?



Thank you


Hi Shane,



Make sure that what you are pulling into the query is actually the name of your notification that triggers the email to be sent.   attachment.addQuery('name', 'contains', 'notificationName'). For example, my notification's name is "email to vendor- record created" so I have the query looking for a notification that contains 'email to vendor'. Also, make sure that the attachments are attached to the actual notification record and not the source record. This should be all you need for it to work.



Thank you,


Yeny