Getting attachment in Email rather than link

habin
Kilo Contributor

Hi ,
I have a requirement to get all the attachment of an incident ticket in the mail notification(not as a link). I was able to send the links of attachments through notification.

Could any one please tell how can I accomplish it.

Thanks in advance.

Habin

18 REPLIES 18

habin
Kilo Contributor

I used the script from http://www.servicenowguru.com/scripting/send-email-notification-attachments/ to send attachments as link in the notification mail.

If anyone has any knowledge of how we can send the attachment file in the notification mail, please give your suggestions and comments.

Thanks,
Habin


Not applicable

You may be able to "copy" the attachments to the outbound email notification - there is a table called sys_email which is essentially the inbound and outbound log. For outbound you may be able to add the attachments to the sys_email entry using the javascript attachement copy function.
Note:

1. I dont know for sure if the email outbound processor will include the attachment - need to test (easy to do - go to the outbound email queue - add an attachement to one of the entries and then resend and see what happens)
2. Even if it does work them I am not sure how you would actually use jevescript to copy the attachments form the incident to the outbound email entry. I dont know at what point it is created - best way would be to create an 'on insert' business rule on this table and then get that to go see if the incident has any attachments and then copy them over - the incident can be found via the Target/instance field on the sys_email table. NOTE though that every notification would then include any attachments that the target record has - so you may want further filtering criteria on your business rule.

Hope this helps


Valor1
Giga Guru

I haven't tried this as a mail script (don't think it will work), but all you have to do is create a business rule:

Name: Copy attachments from incident
Table: Email [sys_email]
When: after
Insert: true
Condition:


current.mailbox.getDisplayName() == "Outbox" && current.target_table == 'incident'

Script:

Packages.com.glide.ui.SysAttachment.copy(current.target_table, current.instance, current.getTableName(), current.sys_id);


marcguy
ServiceNow Employee
ServiceNow Employee

Managed to achieve this with a BR on the sys_email table, before insert:
This also marks the attachment as being sent already so that we don't constantly send again.

//gs.log('getting attachments if any');
var myInc = current.instance;

var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',myInc);
gr.addQuery('u_sent',false); //look for attachments that haven't been sent
gr.query();
while (gr.next()) {
gr.u_sent = "true"; //mark the attachment as already sent so we don't send again
//gs.log('found ' + gr.table + gr.table_sys_id);
gr.update();
var table = gr.table_name;
}
gs.print ('Looking for attachment');

Packages.com.glide.ui.SysAttachment.copy (table, current.instance, 'sys_email', current.sys_id);

gs.print ('Copied any found attachments to email');