2021.2

Table Of Contents
Cloning a section based on data and assigning a background PDF
This script clones a section based on data fields. It disables the source section first and then
calls the addPolicy function. addPolicy clones the section, renames it and sets a PDF from the
resources as its background. It explicitly enables the clone and then adds it to the Print context.
var printSections = merge.template.contexts.PRINT.sections;
merge.template.contexts.PRINT.sections["Policy"].enabled = false;
if(record.fields.policy_a == 1) {
addPolicy('a');
}
if(record.fields.policy_b == 1) {
addPolicy('b');
}
function addPolicy(policy){
var resourceUrl = 'images/policy-' + policy + '.pdf';
var clone = printSections["Policy"].clone();
clone.name = "policy_" + policy;
clone.background.url = resourceUrl;
clone.enabled = true;
printSections["Policy"].addAfter(clone);
}
Control Script: Securing PDF attachments
The Print context can be attached to an email in the form of a PDF file and secured with a
password. This can be done without a Control Script, see "Email attachments" on page538
and "Email PDF password" on page538.
With a Control Script, you can do the same, and more: the attachment can be split into multiple
attachments (see Parts). Each attachment may have a different (or no) set of passwords, so you
could mix secured and unsecured attachments in a single email. This topic shows how.
For information about Control Scripts in general, see "Control Scripts" on page913 and
"Control Script API" on page1405. If you don't know how to write scripts, see "Writing your own
scripts" on page877.
Setting passwords in script
To set a password on a Print section in a Control Script, the script should first retrieve the Print
section/s using merge.template.contexts.PRINT.sections or merge.context.sections (also
see the example below).
Page 927