2022.2

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 assigning a background PDF
Thisscriptclonesasectionbasedondatafields.Itdisablesthesourcesectionfirstandthencallsthe
addPolicyfunction.addPolicyclonesthesection,renamesitandsetsaPDFfromtheresourcesasits
background.ItexplicitlyenablesthecloneandthenaddsittothePrint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PrintcontextcanbeattachedtoanemailintheformofaPDFfileandsecuredwithapassword.
ThiscanbedonewithoutaControlScript,see"Emailattachments"onpage167and"EmailPDFpass-
word"onpage166.
WithaControlScript,youcandothesame,andmore:theattachmentcanbesplitintomultipleattach-
ments(seeParts).Eachattachmentmayhaveadifferent(orno)setofpasswords,soyoucouldmix
securedandunsecuredattachmentsinasingleemail.Thistopicshowshow.
ForinformationaboutControlScriptsingeneral,see"ControlScripts"onpage398and"ControlScript
API"onpage815.Ifyoudon'tknowhowtowritescripts,see"Writingyourownscripts"onpage368.
Settingpasswordsinscript
TosetapasswordonaPrintsectioninaControlScript,thescriptshouldfirstretrievethePrintsec-
tion/susingmerge.template.contexts.PRINT.sectionsormerge.context.sections(also
seetheexamplebelow).
Next,thescriptcansplittheattachments,ifneeded(see"Parts:splittingandrenamingemailattach-
ments"onpage402),anditcansetapasswordoneachsection.Forexample:
Page 408