The CreatorCon Call for Content is officially open! Get started here.

How to include attachment in Approval notification email

james_ledger
Tera Contributor

Hi

When a user raises a request item in the catalog, they have to attach a document to this, and when they submit the form it sends off an approval email. How can I get this document attached to the approval email that sends off?

Thanks

James

4 REPLIES 4

Ankush Jangle1
Kilo Guru

Hello,

 

you can try this code

If the attachment is uploaded on requested item, you don't need getTaskId(). I assume your notification is created on the Approvals table (sys_approval_approver). Change the following line in the above code and I think you should be all set.

 

 

var gr = new GlideRecord('sys_attachment');

gr.addQuery('table_sys_id', current.sysapproval.sys_id);   // current.sysapproval field should have the                                                                                                requested item object.

gr.query();

 

 

Mark it Correct/Helpful if it Helps you

Harish KM
Kilo Patron
Kilo Patron

Use this script in BR(Approval table)

getAttachment();

function getAttachment()

 

{

 

var attachment = new GlideRecord('sc_req_item');

 

attachment .addQuery('sys_id', current.sysapproval);

 

attachment .query();

 

  while(attachment .next()) {

 

  GlideSysAttachment.copy("sc_req_item", attachment .sys_id, "sysapproval_approver", current.sys_id);

 

  }

 

}

Regards
Harish

Rishabh Jha
Mega Guru

Hi @james.ledger ,

If you're using an email notification to send the email, you can check the "Include Attachments" checkbox on the notification, and it'll automatically include all the attachments of the current context record to the email.

find_real_file.png

Thanks & Regards,

Rishabh Jha

Aavenir (https://www.aavenir.com/)

Jaspal Singh
Mega Patron
Mega Patron

Hi James,

 

Does this needs to be sent only for specific approval records or for all scenarios of approval record?

If there is a need for all approval notifications then you can simply use the Include Attachments checkbox available at each notification level. You can find that in the What it will contains tab of the notification

find_real_file.png

 

If this needs to be specific then you can create a mail script as below from System Notificaiton >> Email >> Notification Email script named: getattachments

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

    var gr = new GlideRecord('sys_attachment');
    gr.addQuery('table_sys_id', current.sysapproval);
    //gr.addQuery(''); //apply additional query here to restrict it to specific approval records
    gr.query();
    while (gr.next()) {
            template.print('Attachments: <a href="http://' + gs.getProperty("instance_name") + '.service-now.com/sys_attachment.do?sys_id=' + gr.sys_id + '">' + gr.file_name + '</a>\n');        
    }
})(current, template, email, email_action, event);

Then call the mail script in the notification body in format

${mail_script:getattachments}