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.

Add Variable attachment to notification email

SM123
Tera Expert

Hi,

I'm here after referring 

Adding attachments to Email - ServiceNow Community

I'm tring attach dynamic vitiable attachment attached during form submission to OOB approval email notification. below is my After insert BR on sys_email table. But it isn't working. could anyone please help me.

 

(function executeRule(current, previous /*null when async*/) {


    // Get the approval record (sysapproval_approver)
    var approverGR = new GlideRecord(current.target_table);
    if (!approverGR.get(current.instance))
        return;
    var catItem = ritm.cat_item.getRefRecord();
    if (!catItem || catItem.name !== 'Server Test')
        return;

    // Get the attachment linked to the catalog variable (ZZ_YYsc_req_item)
    var attachGR = new GlideRecord('sys_attachment');
    attachGR.addQuery('table_sys_id', ritm.sys_id);
    attachGR.addQuery('table_name', 'ZZ_YYsc_req_item');
    attachGR.query();

    if (attachGR.next()) {
        var emailAttach = new GlideRecord('sys_email_attachment');
        emailAttach.initialize();
        emailAttach.attachment = attachGR.sys_id;
        emailAttach.file_name = attachGR.file_name;
        emailAttach.source = 'notification';
        emailAttach.content_disposition = 'attachment';
        emailAttach.email = current.sys_id;
        emailAttach.insert();
    }

})(current, previous);

malika123_0-1748116129555.png

Thank You

 

2 REPLIES 2

phgdet
Mega Sage
Mega Sage

Hi @SM123
Have you checked the Include attachments on your notification record yet?

Screenshot 2025-05-26 at 11.43.13.png

Ram97
Tera Contributor

@SM123 Is there any specific reason for using BR? I would recommend you to use Flow Designer to achieve this. This is easy and convenient way. Please let me know if you need any help with this. 

Regards,
Ram Ardhani.