1.4

l merge.section is only defined when when the output channel is Web. To make sure
that it is defined, use the following if statement: if (merge.channel ==
Channel.WEB && merge.context.type == ContextType.WEB) {... }.
l When using merge.context.sections keep in mind that for example 'Section X'
might only exist in your Print context, so using merge.context.sections
['Section X'] without enclosing it in the if statement if
(merge.context.type == ContextType.PRINT) {} will yield an error when
the script runs for other contexts. Instead of enclosing it in an if statement, you can use
the template object to access a specific context:
merge.template.contexts.PRINT.sections['Section X'] .
Sample scripts
Conditionally skipping or printing Print sections
var printSections = merge.template.contexts.PRINT.sections;
printSections['Section EN'].enabled = false;
printSections['Section FR'].enabled = false;
if(record.fields.Language === 'FR'){
printSections['Section FR'].enabled = true;
} else {
printSections['Section EN'].enabled = true;
}
Selecting different sections for Print output and Email PDF attachment
var printSections = merge.template.contexts.PRINT.sections;
if(merge.channel === Channel.EMAIL){
printSections['Section 1'].enabled = false;
printSections['Section 2'].enabled = true;
}
if(merge.channel === Channel.PRINT){
printSections['Section 1'].enabled = true;
printSections['Section 2'].enabled = false;
}
Setting the name of Email PDF attachments
var section = merge.template.contexts.PRINT.sections['Section 1'];
section.part = 'Invoice ' + record.fields['InvoiceNo'];
Page 216