Value Compare Conditional
Overview
The ValueCompare Conditional is used to compare numeric values. It supports all numeric comparison operators: <, >, <=, >=, ==, and !=. See below for details on how to construct a ValueCompare conditional.
Schema
| key | type | required | description |
|---|---|---|---|
| type | string |
required | A string defining the type of conditional as valueCompare. |
| operator | string |
required | A string that defines the comparison operation to perform. Valid values are <, >, <=, >=, ==, and !=. |
| value | number |
required | The value to be used as the left operand in the comparison. |
| valueQuery | string |
optional | A JSONata query whose result will be used as the right operand in the comparison. The query must resolve to a single string, integer or float value. If a string, it may contain currency and comma separators (i.e. $12,345.56). If valueQuery is not provided, the data associated with the object containing the conditional is used for comparison. For example, a textOptions defined in a style on a table's column may include a conditional. If the valueQuery property is not defined, the conditional will be evaluated for each row in the table. An example of this is provided below. |
Example
The following example shows how to alter text formatting in a table column base on a value comparison. The Total column contains a style with a conditional textOptions that will highlight any value that is less than 100 in red and any value that is greater than 400 in green.
{
"type": "Table",
"style": {"layoutOptions": {"width": 250}},
"columns": [
{
"rowDataQuery": "sku"
},
{
"rowDataQuery": "qty"
},
{
"rowDataQuery": "total",
"rowStyle": {
"textOptions": [
{
"fontColor": "Red",
"format": {
"type": "float",
"formatString": "C2"
},
"condition": {
"type": "valueCompare",
"operator": "<",
"value": 100
}
},
{
"fontColor": "Green",
"format": {
"type": "float",
"formatString": "C2"
},
"condition": {
"type": "valueCompare",
"operator": ">=",
"value": 400
}
}
]
}
}
],
"headerRows": {
"data": [["SKU", "Qty", "Total"]]
},
"rows": {
"dataQuery": "sales",
"style": {
"textOptions": [
{
"backgroundColor": "LightGray"
},
{
"backgroundColor": "White"
}
]
}
}
}
An example output of the table defined above showing conditional text formatting using a value comparison:
