Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to add attachments in Email content.

Ashutosh4
Tera Contributor

I have a requirement where I need to send multiple fillable documents to end users based on the location during onboarding flow.


I have created a Life cycle event for the complete process.

In one specific step I need to send out different documents for end users based on location.
I created audience based on the location and then using it in the activities to Trigger notifications , which is workign fine but I am not able to add Attachments in it.

I added as an attachment in the notification and it is not working , I thought of using link and adding attachment but that option is only present in notifications and not email content.

Ashutosh4_0-1739378326864.png

Any help is appreciated.

Thank you!

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Ashutosh4 We faced the similar situation when we needed to send emails with attachments. We resolved this by creating an onBefore Insert business rule on the sys_email table. This BR triggers for specific case table (sn_hr_le_case) and in the script copies attachment from sys_attachment table to sys_email_attachment table.

 

Here is the script.

 

GlideSysAttachment().copy("sysevent_email_action", "<sys_id>", 'sys_email', current.getValue("sys_id"));

    var sysId = <sys_id>
    var ids = sysId.length;

    var attachment = new GlideRecord("sys_email_attachment");

    if (ids > 0) {

        for (var i = 0; i < ids; i++) {
	    attachment.newRecord();
            attachment.attachment = sysId[i];
            attachment.file_name = attachment.attachment.file_name.toString();
            attachment.email = current.getValue("sys_id");
            attachment.source = "notification";
            attachment.content_disposition = "attachment";
            attachment.insert();
        }
    }

Hope this helps.

Ashutosh4
Tera Contributor

There can be different notifications as well which are using sn_hr_le_case table in that situation how shall I distinguish ?