Attach the dynamically generated report (excel) to the email body of the notification without HREF

Sujatha V M
Kilo Patron
Kilo Patron

Hello all, 

 

I have generated a report using the script which gets add to the Attachment [sys_attachment] table. 

 

Using this sys_id, I'm able to attach the file as HREF in email notification. By having the URL it requires authentication, if not logged in to download the file. 

 

Instead is there a way to attach the dynamically created report to the email body using mail script or directly so that the customer can download it from mail itself. 

 

Appreciate your inputs or help on it.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.
5 REPLIES 5

Amit Pandey
Kilo Sage

Hi @Sujatha V M 

 

To send a physical attachment dynamically, you have to create a Business rule to add attachment as physically in the notification.

Create Business Rule on Email table with the following details:

Table: Email [sys_email]

When: Before

Insert: True

Condition: Mailbox is Outlook 

                   AND

                   Any other condition to match your requirement

Script:

var grAttachment = new GlideRecord('sys_attachment');
grAttachment.get('<your_attachment_sys_id>'); //replace <your_attachment_sys_id> your attachment sys_id
var attContent = new GlideSysAttachment().getContentStream(grAttachment.sys_id);
new GlideSysAttachment().writeContentStream(current, grAttachment.getValue('file_name'), grAttachment.getValue('content_type'), attContent);

 

Please mark my answer helpful and correct.

 

Regards,

Amit

 

@Amit Pandey Thank you for the response. But my attachment sys id not a static one. 

 

The report is generated using the Scheduled job which adds the excel file to "Attachment" table and from there I would like to add it to the email body of the notification. 

 

Any help is appreciated on it. 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Yes, so when the scheduled job adds the file to attachment table, you will get the sys_id of the attachment. Now, you have to pass that sys_id in line 2.

 

Regards,

Amit

Yes I'm able to get that point but attachments are not getting attached to the emails. 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.