addAttachment()
Last updated 5/03/2026
Definition
Examples
Adding attachments to a mail merge
This code demonstrates how to automatically include submission attachments in a mail merge. The function must be attached to the Do Merge Record event of the mail merge record in order to execute during the email generation process.
When the mail merge processes each record, the function checks whether any attachments are associated with that submission. If attachment exists, it loops through each file, converts it into
a properly formatted Data URI using
After all attachments have been processed, the function returns a successful result, allowing the mail merge process to continue and send the email with all relevant files included.
function DoAddSubmissionAttachments(five: Five, context: any, result: FiveError): FiveError {
if (context.Attachments && context.Attachments.length > 0) {
for (let i = 0; i < context.Attachments.length; i++) {
const attachment = context.Attachments[i];
five.addAttachment(five.toDataURL('application/pdf', attachment.file), attachment.name);
}
}
return five.success(result);
}
function DoAddSubmissionAttachments(five, context, result) {
if (context.Attachments && context.Attachments.length > 0) {
for (let i = 0; i < context.Attachments.length; i++) {
const attachment = context.Attachments[i];
five.addAttachment(five.toDataURL('application/pdf', attachment.file), attachment.name);
}
}
return five.success(result);
}