Logical Functions
The following is the sample JSON for all the examples
data = {
"company_name": "Nakatomi Trading Corp",
"total_amount": 82542.56,
"date": "2021-09-30",
"items": [
{
"name": "Brand Guide",
"man_hour": 2,
"unit": "hour",
"unit_price": 120.0,
"item_total": 240.0
},
{
"name": "Software Development",
"man_hour": 17,
"unit": "hour",
"unit_price": 20.0,
"item_total": 340.0
},
{
"name": "Landing Page Design",
"man_hour": 5,
"unit": "hour",
"unit_price": 20.0,
"item_total": 80.0
}
]
}iif
The iif() function returns a value if a condition is true, or another value if a condition is false
Usage
iif(`condition`, `true_if_value`, `false_if_value`)Parameters
| Parameter | Type | Description |
| condition | boolean | The value to test |
| true_if_value | string | The value to return if condition is true |
| false_if_value | string | The value to return if condition is false |
Example
{{ iif(data.total_amount>100, "The value greater than 100", "The value less than 100") }}Output
The value greater than 100miif
The miif() function returns a value if a condition is true. It supports multiple conditions.
Usage
miif(`condition1`, `value1`, `condition2`, `value2`, `condition3`, `value3`,...., `default_value`)Parameters
| Parameter | Type | Description |
| condition1 | boolean | The first value to test |
| value1 | string | The first value to return if condition is true |
| condition2 | boolean | The second value to test |
| value2 | string | The second value to return if condition is true |
| condition3 | boolean | The third value to test |
| value3 | string | The third value to return if condition is true |
| ... | More conditions and values | |
| default_value | string | The default value to return if all conditions do not meet |
Example
{{ miif( data.total_amount>100, "Tier 1 - greater than 100", data.total_amount>200, "Tier 2 - greater than 200", "not in range") }}Output
Tier 2 - greater than 200getValue
The getValue() function returns a value of an object using a field, it returns empty(or default_value) if value is null or undefined
Usage
getValue(`object`, `field`, `default_value`)Parameters
| Parameter | Type | Description |
| object | object | An object |
| field | string | A field name |
| default_value | string | returns ’’(empty) if value is null or undefined |
Example
{{ getValue( data.items.find((e)=> e.name==='Software Development' ), 'man_hour','-' ) }}Output
17