Attaching a CSV File to a Notification

Julian Reis
Tera Contributor

I am currently working on a script action in ServiceNow where I generate a CSV file. My goal is to attach this CSV file to a notification in the "sysevent_email_action" table. Is it possible to attach the CSV file from the script action to the notification? If so, could you provide any insights or steps on how this can be done efficiently? Any guidance would be greatly appreciated! Thank you!

4 REPLIES 4

JenniferRah
Mega Sage

I'm not sure I understand why you would want to generate a CSV to add to a notification record. Are you wanting it to be added to the email that is sent? Is that the goal?

Julian Reis
Tera Contributor

Yes, exactly, that is the goal! 🙂 The CSV file is generated in the script action, and now I want to send it via a notification. A colleague of mine generated the CSV in the script action and created the email directly from the script action. However, I want to handle sending the email through a notification instead.

I think you will want to add it to the sys_email_attachment table. I have a business rule that runs on the sys_email_log table and has a condition to narrow it to specific emails. Then it adds an attachment to that email like this: 

 

        var att = new GlideRecord('sys_email_attachment');
        att.initialize();
        att.attachment = gr.sys_id; //In my case, this links to a specific attachment in the sys_attachment table
        att.content_disposition = "attachment";
        att.action = 'attached_to_target_record';
        att.email = current.email;
        att.insert();

 

Now, my code adds an attachment that's already uploaded into the sys_attachment table. Since you are generating yours dynamically, the code will be slightly different, but hopefully that gets you started. 

Ankur Bawiskar
Tera Patron
Tera Patron

@Julian Reis 

Ideally that file needs to be attached to the target record on which notification is being sent.
Then when you use Include attachment checkbox that file will be sent over via email

what's your business requirement?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader