1.6

Table Of Contents
var printSections = merge.template.contexts.PRINT.sections;
var numClones = record.tables['detail'].length;
for(var i = 0; i < numClones; i++){
var clone = printSections["Section 1"].clone();
clone.name = "my_section_clone_" + i;
printSections["Section 1"].addAfter(clone);
}
Cloning a section based on data and assign 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);
}
template
The template object represents the template with all its contexts and sections. It is used
frequently in Control Scripts (see "Control Scripts" on page545 and "Control Script API" on
page797).
It is retrieved via the merge object: merge.template (see "merge" on page799).
Which contexts are available in the template can be queried using merge.template.contexts.
To get access to a specific context, you have to specify the ContextType (see "ContextType" on
page810).
Page 808