last attachment in notification

Vedavalli
Tera Expert

Hi

Is there any option to send the last attachment from multiple attachments in the email notification?

Thank you.

1 ACCEPTED SOLUTION

@Vedavalli 

you can use email script but it will only include link to the latest attachment and not the actual file.

if you want to include file in outbound email then link I shared should work

If you want to include link to the latest attachment added to record then use email script

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here
    template.print('Latest attachment link <br/>');
    var gr = new GlideRecord("sys_attachment");
    gr.orderByDesc('sys_created_on');
    gr.addQuery("table_sys_id", current.sys_id);
    gr.setLimit(1);
    gr.query();
    if (gr.next()) {
        var instance_name = gs.getProperty('glide.servlet.uri');
        template.print('Click <a href="' + instance_name + 'sys_attachment' + '.do?sys_id="' + gr.sys_id + '">' + gr.file_name + '</a> to view the Attachment.');
    }

})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@Vedavalli 

there is no direct OOTB way for this

But I have shared solution on how to include latest attachment from record in outbound email

see this link and enhance your script

Adding latest attachment from sys_attachment table to sys_email record 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar 

can we use email scripts?

@Vedavalli 

you can use email script but it will only include link to the latest attachment and not the actual file.

if you want to include file in outbound email then link I shared should work

If you want to include link to the latest attachment added to record then use email script

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here
    template.print('Latest attachment link <br/>');
    var gr = new GlideRecord("sys_attachment");
    gr.orderByDesc('sys_created_on');
    gr.addQuery("table_sys_id", current.sys_id);
    gr.setLimit(1);
    gr.query();
    if (gr.next()) {
        var instance_name = gs.getProperty('glide.servlet.uri');
        template.print('Click <a href="' + instance_name + 'sys_attachment' + '.do?sys_id="' + gr.sys_id + '">' + gr.file_name + '</a> to view the Attachment.');
    }

})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Vedavalli 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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