Skip to content

Conditionals

Some elements in a report template, including all component types, TextOptions and external report options, support condition objects. These are used to alter a report at time of render based on the data provided. The following describes the various types of supported conditionals as well as examples of how they are used.

It may be helpful to include data specifically for the purpose of controlling layout in your report. For example, a report may be formatted differently depending on the financial institution. The FI identifier could be included in the data for the sole purpose of conditional comparisons and not be output in the final report.

Component Conditions

A condition can be included on any component in a report template. When rendering, the engine will evaluate the query and include the component in the output only when the associated query resolves to true. This allows for building dynamic reports that render differently depending on the data supplied at time of render.

TextOptions Conditions

Conditions can also be applied to any TextOptions in a report. This is commonly used when defining an array of TextOptions. In this case each TextOptions element in the array is evaluated in order. The first item with a conditional value that resolves to true will be applied to the text in the component.

The example below shows how to change the color of a font depending on a specific value. In this case, text will be drawn in red if the value returned from the JSONata query totalSales is less than 0 and in green if it is greater than or equal to 0.

"textOptions": [
    {
        "color": "Red",
        "condition": {
            "type": "valueCompare",
            "operator": "<",
            "value": 0,
            "valueQuery": "totalSales"
        }
    },
    {
        "color": "Green",
        "condition": {
            "type": "valueCompare",
            "operator": ">=",
            "value": 0,
            "valueQuery": "totalSales"
        }
    }
]

External Report Option Conditions

External options files can include a condition. This is helpful when a report should be styled differently depending on data supplied at time of render.

External Component Conditions

External component files can also include a condition. This is helpful when a report should contain different content depending on the data supplied at time of render.

Global Conditional

A conditional may be defined once in a report template and then later referenced by its Identifier. Below is an example of a report template containing two different conditionals that can be reused later in the report.

{
    "id": "CALL_CODE",
    "name": "Call Code",
    "description": "Portfolio Summary By Call Code",
    "creator": "Aaron Watson",
    "conditionals": [
        {
            "id": "opt1",
            "type": "stringCompare",
            "operator": "isEqual",
            "valueQuery": "REPORT_OPTIONS",
            "string": "OPT1"
        },
        {
            "id": "opt2",
            "type": "stringCompare",
            "operator": "isEqual",
            "valueQuery": "REPORT_OPTIONS",
            "string": "OPT2"
        }
    ]
}

To reference one of these conditionals, simply use its identifier as shown below:

{
    "type": "Text",
    "text": "Sales Report",
    "condition": "opt1"
}