Conditional print sections

conditional-printing

A classic approach to dynamically switch messages is to enable or disable sections for printing. OL Connect’s Designer contains a basic condition wizard and a scripting API to toggle the visibility of print sections. In version 2021.1 we revamped the wizard. It allows conditions to validate against multiple data fields and it provides predefined operations based on the field type (e.g. check if a boolean field is true or is false).

The following example shows how to use the new wizard to skip or print sections for a university admission letter.

The template

The templates contains the following sections:

  • Accepted
  • Rejected
  • Consent

The first section (Accepted) contains a message for students that are admitted to Green University, the second section is for less fortunate applicants. The third section contains a parent/guardian consent form for admitted students under 18 years of age.

The data model of the template contains information about the applicant and their admission status. The data (CSV) is read via a DataMapper configuration. This creates a data field for each column in the data file. It is also used to set the type of the admitted field to boolean (true/false) and created an integer field for the age of the applicant.

Example data model.

Setting up conditions

In order to toggle the visibility of the sections a condition needs to be set for each.

Basic condition

For the Accepted and Rejected sections we can setup a basic condition validating against a single data field (admitted).

To set up the condition for the Accepted section:

  1. Right click the Accepted section in the Print section of the Resources panel and choose Make Conditional… from the contextual menu.
  2. Select the admitted field for the first Field rule.
  3. Set its condition to is true.
  4. Click OK to save your changes. A new entry is added to the Scripts view.
Condition setup view.

When the condition is met (i.e. the admitted field is true) the section will automatically be printed, otherwise it will be skipped i.e. not printed. In case the section is skipped, a red alert decorator is shown on the icon of the respective section in the Resources view.

Resources view.

Now one needs to setup a similar condition for the Rejected section. Repeat steps 1 and 2 but set the condition to is false. In this scenario the section will be printed then the value is false and for other scenarios it will be skipped.

Invoke the Preview mode and browse through the records. The decorators for the Accepted and Rejected sections will be turned on and off indicating their print status.

Extended condition

The Consent section needs to be shown for accepted applications that are under 18 years of age. For these we need to validate against two fields, being: accepted and age.

To set up the condition for the Consent section:

  1. Right click the Content section in the Print section of the Resources panel and choose Make Conditional… from the contextual menu.
  2. Select the admitted field for the first Field rule.
  3. Set its condition to ‘is true’.
  4. Click the Add Data Rule (green plus symbol) to add an extra rule.
  5. Select the age field.
  6. Set the condition of the field to Less than and enter 18 in the subsequent input field.
  7. Click OK to save your changes.
Condition setup view.

The scripts

The Scripts view now contains three condition scripts, one for each section. Double click the script entry to invoke the wizard dialog.

The scripts reside in the Control group of the Scripts view. Control Scripts run before all other script types and are typically used to control the setup/structure of the template.

Scripts view.

Toggle to the Preview mode and browse through the records to see the print status decorator of the sections turn on and off based on the value of the admitted field.

Preview mode.