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

Harish Murikina
Tera Guru

In your case what your doing is your just giving the url of the document location that is why its asking login credentials to get attachment.



Write below script to to attach file .


<mail_script>


var uid = current.sys_id;


var gr = new GlideRecord('sys_attachment');


  gr.addQuery('table_sys_id',uid);


  gr.query();                                                                                            


  while(gr.next())


  {


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



}


</mail_script>



You must check the check box "Include attachments:"



Regards,


Harish.


Hi Harish,



Thank you for your response. I tried the email script you suggested and made sure to click on "include attachments" but it is not working. I think that the 'include attachments' button is to attach documents from the source record but I don't have anything attached in there. I have the attachments in the notification record which is where I need the documents to be pulled from... I also put the email script in a function and tried it again and still didn't get any results... do you have any other ideas? I'm so lost...



Thank you for your help!


Yeny Garcia


Brad Tilton
ServiceNow Employee
ServiceNow Employee

You could try writing a script that copies the attachment over to your source record so it gets sent out with the email. Another option would be to copy the attachment from the notification record over to the sys_email record generated for that notification. If the attachment exists on the sys_email record it automatically gets sent out as an attachment on the email.


Hi Brad,



I wrote a business rule to copy the attachments from the notification record to the sys_email, unfortunately it's not working for me. I included a screenshot... what am I doing wrong?... this is a eureka version if that makes any difference.. thank you for your help!



br.PNG