Conditional Formatting

Conditional Formatting

Applies to: Kyvos Reporting


You can use scripting in Kyvos Reporting to apply conditional formatting, suppress rows, or perform conditional calculations during report execution. Scripting is written in JavaScript and is typically applied at the Detail section level using events such as OnFormat, OnDataInitialize, and OnFetchData.

Conditional Formatting

You can use script to dynamically highlight or show shapes based on data values. For example, to highlight a field when its value changes compared to the previous row:

Steps:

  1. Add a TextBox (e.g., txtBox) in the ReportHeader and set:

    • Visible = False

    • Text = "-999" (a default value unlikely to occur)

  2. Add a Shape (e.g., Shape1) around the field (e.g., dbField) and configure it as a red ellipse.

  3. Use the following script:

Object: Detail
Event: OnFormat

function OnFormat() { if ( rpt.Sections("ReportHeader").Controls("txtBox").text != "-999" && rpt.Fields("dbField").value != rpt.Sections("PageHeader").Controls("txtBox").text ) { rpt.Sections("Detail").Controls("Shape1").visible = true; } else { rpt.Sections("Detail").Controls("Shape1").visible = false; } rpt.Sections("PageHeader").Controls("txtBox").text = rpt.Fields("dbField").value; }

Conditional Suppression of Rows

To hide rows based on a field value (e.g., if Name is null), you can:

Method 1: Without Scripting

  • Set Visible = False for the control

  • Set Height = 0 in the Properties window

Method 2: Using Scripting

Object: Detail
Event: OnFormat

function OnFormat() { if (rpt.Fields("Name").value == null) { rpt.Sections("Detail").visible = false; rpt.Sections("Detail").height = 0; } else { rpt.Sections("Detail").visible = true; rpt.Sections("Detail").height = 285; } }

Important

For height changes to take effect, ensure CanGrow is set to False on the Detail section. If set to True, the report engine overrides the scripted height.

Conditional Calculation

You can create custom accumulators to perform conditional summation based on data values. For example, summing values based on Account_type:

Object: Report
Event: OnDataInitialize

function OnDataInitialize() { rpt.Fields.add("valueA"); rpt.Fields.add("valueB"); rpt.Fields("valueA").value = 0; rpt.Fields("valueB").value = 0; }

Object: Report
Event: OnFetchData

function OnFetchData(eof) { if (rpt.Fields("accType").value == "A") { rpt.Fields("valueA").value = parseFloat(rpt.Fields("valueA").value) + rpt.Fields("Amt").value; } else { rpt.Fields("valueB").value = parseFloat(rpt.Fields("valueB").value) + rpt.Fields("Amt").value; } rpt.Sections("gfDEPT").Controls("txtACC_A").dataValue = rpt.Fields("valueA").value; rpt.Sections("gfDEPT").Controls("txtACC_B").dataValue = rpt.Fields("valueB").value; }

This script:

  • Adds two custom fields valueA and valueB.

  • Aggregates amounts based on account type.

  • Displays the result in the respective group footer controls (txtACC_A, txtACC_B).

Hiding Page Header and Footer in Studio Reports

Kyvos Reporting allows designers to conditionally hide the Page Header and Page Footer sections using scripting and control tagging.

Steps to Configure:

  1. Assign Tag to Control

    • Set the XmlTagName property of a label or field control to a value (e.g., Header_TAG) that indicates the need to hide the header/footer.

  2. Access Script Editor

    • Open the script window in Kyvos Reporting Studio.

  3. Add Page Event

    • Select the Page Header or Page Footer section.

    • Use the pageEvent property to specify the event string that matches the XmlTagName tag (e.g., Header_TAG).

  4. Write a Script to Hide the Section

    var event = rpt.Sections("PageHeader").pageEvent; if (event.contains("Header_TAG")) { rpt.Sections("PageHeader").visible = false; } else { rpt.Sections("PageHeader").visible = true; }

    Repeat similarly for PageFooter if needed.

Copyright Kyvos, Inc. 2026. All rights reserved.