Skip to main content

DoAddSubmissionAttachments Function

Last updated 29/01/2024

Before the Submission Received mail merge can be created we need to have the ability to attach attachments to the Submission Received mail merge. The
DoAddSubmissionAttachments()
will attach the documents that are attached to the Submissions form to the Submission Received mail merge.


The
DoAddSubmissionAttachments()
is attached to the Do Merge Record event on the Submission Received mail merge and will execute when the Save button is clicked on the Submissions form and merges the documents into the email before the mail merge is sent.


When working in Five's Code Editor you will be interacting with Five's API. In the
DoAddSubmissionAttachments()
you will be using the following functions and properties.


is a function used on the
Five
object that merges the attachments with the email.


is a function used on the
Five
object to embed small files inline into the email.


- is a function used on the
Five
object that returns a indicating success.

1. Click Logic in the menu.

2. Click Code Editor in the sub-menu.


Code Editor menu item
Figure 1 - Code Editor menu item

Add the DoAddSubmissionAttachments Function

1. Click the Add New Code button.


Add New Code button
Figure 2 - Add New Code button

2. Type DoAddSubmissionAttachments in the Function ID field.

3. Click the OKAY button.


OKAY button
Figure 3 - OKAY button

4. Click the Copy button on the code block below.

JavaScript
DoAddSubmissionAttachments

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);
}


5. Paste the code block over the template in Five's Code Editor.

6. Click the Save Current Tab button.


Save Current Tab button
Figure 4 - Save Current Tab button