Conditional design elements

Avatar
Conditional design elements

Conditional design elements

When creating personalized documents one often needs to make decisions based on data. A common example is showing/hiding one or more paragraphs depending on a field’s value. To achieve this OL Connect Designer 2021.1 comes with a wizard to simplify setting up these conditional elements. It allows conditions to check 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).

Show/hide paragraphs

In this example you’ll learn how to conditionally show one or more paragraphs based on data. It is a simple way to toggle information while the overall look and feel of the letter is untouched. Note that conditions are not limited to paragraphs they can be set for any element including headings, images, tables and divs.

The following image shows a letter from an insurance company. The conditional elements are marked with a background color (yellow, blue and red).

The yellow element should be shown when the model_name data field is set to request-for-contact. The blue paragraph is shown when the respective field is set to file-reassignment and the red paragraphs when it is set to denial-no-coverage.

To turn the yellow paragraph in a conditional element:

  1. Right mouse + click the paragraph and choose Make Conditional… from the contextual menu. The wizard appears.
  2. Set the Action to: Show
  3. Make the following settings for the Field rule:
    1. Field: model_name
    2. Condition: Equal to
    3. Value: request-for-contact
  4. Click OK to save the new script.

Tip! Entering a meaningful name for the script will help you to identify it in the Scripts view.

By default the wizard assigns a unique class name (hence the dot prefix: .conditional-script) to the element. This is used by the script to locate the element when it needs to apply the logic. On the initial invocation of the wizard one can overwrite the default selector with a custom value. The value will be assigned to the element and used for the Selector of the script.

Note! In case the element already had an class name and/or ID the wizard will use that information.

The same steps are used to create a conditional script for the blue paragraph but with a different value for the model_name.

Multiple paragraphs with the same condition

For the red text the approach is slightly different as it entails two paragraphs for which the visibility is driven by the same data field. The easiest approach is to assign both paragraphs the same CSS class name before invoking the wizard.

To set the class name for the paragraphs:

  1. Place the cursor in the first paragraph.
  2. Enter a class name in the Class field of the Attributes view (typically located in the upper right corner of the editor. In our scenario this name is: denial-no-coverage.
  3. Place the cursor in the second paragraph and enter the same name.

To make the paragraphs conditional:

  1. Right mouse + click the paragraph and choose Make Conditional… from the contextual menu. The wizard appears.
  2. Note that the Selector field states the previously added class name.
  3. Set the Action to Show
  4. Make the following settings for the Field rule:
    1. Field: model_name
    2. Condition: Equal to
    3. Value: denial-no-coverage
  5. Click OK to save the new script.

The new script targets all elements with the .denial-no-coverage class name. As we’ve set this class to both red paragraphs both entries will be shown/hidden by the same script.

More conditions

The above scenario shows an example to show/hide elements based on a single value. The new wizard allows you to add one or more fields to create more complex conditions.

The available conditions depend on the field type. For boolean fields you will be able to check if the value is true or is false and for integer fields you’ll find conditions like Greater than and Less than but also Greater than or equal to and Less than or equal to.

The green plus icon allows the user add Field rules but also rules for runtime Parameters (set via Workflow) and sub-conditions using Groups.



Leave a Reply

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