Skip to content

Data Substitution

The flexibility of the static report solution comes through data substitution. Each report template will include placeholders for data that will be provided at the time of render and substituted by the rendering engine. This data substitution is accomplished in two ways: table data substitution and string substitution. In addition to providing data through a json data file, Reserved Keywords can be used to insert common data elements such as date, time and page numbering.

String Substitution

Report templates can use string substitution to insert data from the report data supplied at report rendering. This can be accomplished by inserting a JSONata query anywhere the renderer expects a string using the format @(ataQuery). An example is shown below.

A text component using string substitution:

{
    "type": "Text",
    "text": "@(year) Sales Report"
}

It is possible to include multiple data queries in a single text element.

{
    "type": "Text",
    "text": "@(month) @(year) Sales Report"
}

And it is possible to include more complicated queries such as calculating sums:

{
    "type": "Text",
    "text": "Total Sales: @($sum(salesTotal))"
}

String substitution also works with filenames in report options and external components:

"externalOptions": [
    {
        "filename": "@(fi_id)/@(branch_id)/Styles.opt.json"
    }
]

Reserved Keywords

Reserved keywords are inserted into text using the $(KEYWORD) format. The following reserved keywords can be used to insert common data into a report:

  • DATE - Inserts the current date in 'M/d/yyyy' format.
  • DATE_LONG - Inserts the current date in 'dddd, MMMM dd, yyyy' format.
  • TIME - Inserts the current time in 'h:mm tt' format.
  • TIME_LONG - Inserts the current time in 'h:mm:ss tt' format.
  • TIME_UTC - Inserts the current time as UTC in 'h:mm tt' format.
  • TIME_UTC_LONG - Inserts the current time as UTC in 'h:mm:ss tt' format.
  • PAGE - Inserts the current page number.
  • PAGE_COUNT - Inserts the report page count.
  • SECTION_BEGIN_[section_name] - Inserts the page number of the first page of the named section.
  • SECTION_END_[section_name] - Inserts the page number of the last page of the named section.
  • SECTION_COUNT_[section_name] - Inserts the number of pages in the named section.

To use these keywords in a report template, use the standard string substitution format. An example is included below:

{
    "type": "Text",
    "text": "Page $(PAGE) of $(PAGE_COUNT)"
}