Attach the dynamically generated report (excel) to the email body of the notification without HREF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 08:10 AM
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.
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 09:35 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 04:04 AM
@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.
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 04:18 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 04:34 AM - edited 04-18-2024 04:54 AM
Yes I'm able to get that point but attachments are not getting attached to the emails.
Sujatha V.M.