Writing an email attachment script
Instead of editing an Email section's properties, or using the Dynamic Attachment Script Wizard, you could write your own scripts to add attachments to an email. Here's how to do that.
-
On the Scripts pane at the bottom left, click New. The Edit Script dialog will start. Click OK a new script appears in the list. Double-click on it to open it.
-
Change the name of the script, so that it reflects what the script does.
-
The selector of the Attachments script should be the head of an Email section, e.g.:
html.HTML_EMAIL[section="myEmailSection"] > head
. -
-
For resources inside the template, specify the file name, including the respective folder in the Resources folder, for example
'images/file.extension'
, or'fonts/myfont.otf'
, etc. -
For external resources, you need the full path to the file, for example:
'file:///c:/resources/attachments/instructions.pdf'
or, for a remote file:'http://localhost:8080/pod/v1/deliverynotes/{8FCEC8BC-72E8-486B-A206-516BF10E21F6}'
.
Use the
append()
function to add a <link> element to the head of the Email section and set itshref
attribute to where the file comes from. For example:results.append("<link rel='related' href='images/letter-CU00048376.pdf'>");
The link doesn't have to be static; you could use data from the record set to build the link, for example:var customerID = record.fields.ID;
results.append('<link rel="related" href="images/letter-' + customerID + '.pdf">'); -
-
Add the
title
attribute to specify a custom attachment name. For example:results.append("<link rel='related' href='images/{8FCEC8BC-72E8-486B-A206-516BF10E21F6}.pdf' title='INV1375461.pdf'>");
-
Click OK to save the script.