Back to all How-tos

Output Sections conditionally

The case we deal here is the one where the sections are output according to a data field value condition.

For example, we have three sections named respectively Letter-Volley, Letter-Other and Invoice. The data field Preference allows us to control what section should be executing based upon its value. So, if the data field Preference value is equal to Volleyball then the Letter-Volley and the Invoice sections are output, else the Letter-Other and Invoice sections are outputted.

Steps

  1. In the Scripts pane, add a Control Script
  2. Open the Control Script and write the following lines:
    var lettertype = record.fields.LetterType;
    if (lettertype == 'service'){
        merge.template.contexts.PRINT.sections['RecallLetter'].enabled = false;
    }
    else {
        merge.template.contexts.PRINT.sections['ServiceLetter'].enabled = false;
    }

In order to test this concept, you can download and open the following resources which are taken from the ‘Connect Foundations’ course.

To see the control script above in action, toggle to the Preview tab in the template view and go through the different records. Notice that a red indicator appears next to the letter/document (in the Resources pane, under Contexts > Print) that is disabled by the script depending on the value of the Preference field.

API Features used in this how-to

Leave a Reply

Your email address will not be published. Required fields are marked *