Loading...

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

ParameterTypeDescription
conditionbooleanThe value to test
true_if_valuestringThe value to return if condition is true
false_if_valuestringThe 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 100

miif

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

ParameterTypeDescription
condition1booleanThe first value to test
value1stringThe first value to return if condition is true
condition2booleanThe second value to test
value2stringThe second value to return if condition is true
condition3booleanThe third value to test
value3stringThe third value to return if condition is true
...More conditions and values
default_valuestringThe 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 200

getValue

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

ParameterTypeDescription
objectobjectAn object
fieldstringA field name
default_valuestringreturns ’’(empty) if value is null or undefined

Example

{{ getValue( data.items.find((e)=> e.name==='Software Development' ), 'man_hour','-' ) }}

Output

17