attachments not being sent with email

faisal_waryum
Tera Expert

Hi, 

 

I am having an issue with a business rule which is on the sys_email table, the email itself is being sent out however the attachment is not being included in the email

this is the script which i have wrote, any guidance would be great 

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

    var grFCR = new GlideRecord('x_spog_new_fcr_application');
    if (grFCR.get(current.instance)) {

        var attachments = grFCR.getValue('invoice_attachments');

        var grAttachment = new GlideRecord('sys_attachment');
        grAttachment.addQuery('table_sys_id', current.instance);
        grAttachment.addQuery('table_name', current.target_table);
        grAttachment.addEncodedQuery("sys_idIN" + attachments);
        grAttachment.query();

        while (grAttachment.next()) {
            var grEmailAttachment = new GlideRecord('sys_email_attachment');
            grEmailAttachment.setValue('action', 'attached_to_target_record');
            grEmailAttachment.setValue('attachment', grAttachment.getUniqueValue());
            grEmailAttachment.setValue('content_disposition', 'attachment');
            grEmailAttachment.setValue('email', current.getUniqueValue());
            grEmailAttachment.setValue('file_name', grAttachment.getValue('file_name'));
            grEmailAttachment.setValue('source', 'notification');
            grEmailAttachment.insert();
        }
    }

})(current, previous);

 
Thanks

1 ACCEPTED SOLUTION

faisal_waryum
Tera Expert

The recipients on the when to send had a new email address this was the issue, a silly error but one i could not predict as the email had changed. 

View solution in original post

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @faisal_waryum 

  1. Check the notification record: Make sure that the "Include Attachments" checkbox is checked in the notification record. Also, make sure that the attachment field is mapped correctly in the email template.

  2. Check the email template: Make sure that the email template includes the attachment field using the correct variable. The variable should be something like ${attachment}, depending on how the attachment field is named in the custom table.

  3. Check the file type: Make sure that the file type of the attachment is supported by the email client that the requestor is using. Some email clients may block certain file types for security reasons.

  4. Check the email size: Some email servers or clients may have limits on the size of attachments that can be sent. Make sure that the attachment size is within the allowed limits.

  5. Check the email logs: Check the email logs to see if there are any errors or warnings related to the attachment. This can help you identify any issues with the email delivery.

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0538138

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

faisal_waryum
Tera Expert

The recipients on the when to send had a new email address this was the issue, a silly error but one i could not predict as the email had changed. 

Hi @faisal_waryum 

 

Is the issue resolved? If yes, please close the thread.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Ankur Bawiskar
Tera Patron
Tera Patron

@faisal_waryum 

what does this field contain?

invoice_attachments

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