TiKiLa Logic Operations

An overview of the logical expressions you can perform with TiKiLa

TiKiLa comes with a bunch of functions that you can use to assess logic. Here’s an overview of the capabilities with some examples:

 

TiKiLa Logic Functions

equals(item_1, item_2)

Asserts if two items are equal and returns true or false. Note: when comparing strings, this function is case-sensitive!

 

Example:

equals(1,2) —> false | equals(4,4) —> true | equals(”hello world”,”hello world”) —> true | equals(”hi”,”HI”) —> false

 

notEquals(item_1, item_2)

The inverse function of equals. Asserts if two items are unequal and returns true or false.

Note: when comparing strings, this function is case-sensitive!

Example: notEquals(1,2) —> true | notEquals(4,4) —> false | notEquals(”hello world”,”hello world”) —> false | notEquals(”hi”,”HI”) —> true

 

greater(number_1, number_2)

This function checks if a number is greater than another and returns true if it is, or false if it is not.

 

Example:

greater(1,2) —> false | greater(2,1) —> true | greater(2,2) —> false

 

greaterOrEquals(number_1, number_2)

This function checks if a number is greater than or equal to another and returns true if it is, or false if it is not.

Example:

greaterOrEquals(1,2) —> false | greaterOrEquals(2,1) —> true | greaterOrEquals(2,2) —> true

 

less(number_1, number_2)

This function checks if a number is less than another and returns true if it is, or false if it is not.

 

Example:

less(1,2) —> true | less(2,1) —> false | less(2,2) —> false

 

lessOrEquals(number_1, number_2)

This function checks if a number is less than or equal to another and returns true if it is, or false if it is not.

Example:

lessOrEquals(1,2) —> true | lessOrEquals(2,1) —> false | lessOrEquals(2,2) —> true

 

if(expression, value_if_true, value_if_false)

This function allows you to create conditional statements. If the expression evaluates to true, the function returns value_if_true, otherwise it returns value_if_false. The logical expression can be any of the other TiKiLa assertions.

Example:

if(greater(2,1) “yes”, “no”) —> “yes” | if(less(4,2), “yes”, “no”) —> “no”

 
 

Example

Example JSON - Copy this to your account to try it out yourself
{"name":"Patch JSON List Logic","description":"An example of TiKiLa Logic functions","nodes":{"start_1":{"type":"start","logging_enabled":false,"error_rules":[],"x":595,"y":285},"stop_1":{"type":"stop","logging_enabled":false,"error_rules":[],"x":1430,"y":792},"input_any_1":{"type":"input_any","logging_enabled":false,"error_rules":[],"x":389,"y":384,"inputs":{"any":{"title":"demo_fb_insights","description":"The any to input","export_enabled":true,"data":[{"campaign_id":"absjf8c1234","clicks":34,"spend":5140,"conversions":7,"status":"ACTIVE"},{"campaign_id":"def63fsh374","clicks":140,"spend":25342,"conversions":26,"status":"ACTIVE"},{"campaign_id":"rh123fetdks","clicks":100,"spend":23470,"conversions":24,"status":"PAUSED"}]}}},"patch_json_list_v3_1":{"type":"patch_json_list_v3","logging_enabled":false,"error_rules":[],"x":873,"y":496,"inputs":{"patches":{"export_enabled":true,"data":[]},"value":{"export_enabled":true}}}},"edges":[{"id":"input_any_1.any:patch_json_list_v3_1.data_list","points":[]},{"id":"patch_json_list_v3_1.patched:stop_1.stop","points":[]},{"id":"start_1.start:patch_json_list_v3_1.patch","points":[]}],"groups":{},"widgets":{},"variables":{},"config":{"capture_inputs_enabled":false,"caching_enabled":false},"tags":[]}
 

Take the following example. We have pulled a list of insights for some campaigns:

Demo Campaign Insights
[
  {
    "campaign_id": "absjf8c1234",
    "clicks": 34,
    "spend": 5140,
    "conversions": 7,
    "status": "ACTIVE"
  },
  {
    "campaign_id": "def63fsh374",
    "clicks": 140,
    "spend": 25342,
    "conversions": 26,
    "status": "ACTIVE"
  },
  {
    "campaign_id": "rh123fetdks",
    "clicks": 100,
    "spend": 23470,
    "conversions": 24,
    "status": "PAUSED"
  }
]
 

Now we want to add a field “spend_too_high” and set it to either true or false depending on some rules: It should be true when the campaign status is ACTIVE and the spend is higher than 20000. In all other cases it should be false.

 

We are going to use the Patch JSON List TiKiLa node which can perform patches for each item in a given list. Our patch looks like this:

Notion image
Patches
{{
    
    if(
        equals(inputData("/status"),"ACTIVE"),
        if(
            greater(inputData("/spend"),20000),
            "true",
            "false"
        ),
        "false"
    )
}}
 

We achieve this by chaining two if-statements together. If the status equals ACTIVE we evaluate the second if-statement. Otherwise we return false. Inside the second if-statement we use the greater function to check if the spend is greater than 20000. If this is the case, we return true, otherwise we return false.

 

The result looks like this:

Result
[
  {
    "campaign_id": "absjf8c1234",
    "clicks": 34,
    "spend": 5140,
    "conversions": 7,
    "status": "ACTIVE",
    "spend_too_high": "false"
  },
  {
    "campaign_id": "def63fsh374",
    "clicks": 140,
    "spend": 25342,
    "conversions": 26,
    "status": "ACTIVE",
    "spend_too_high": "true"
  },
  {
    "campaign_id": "rh123fetdks",
    "clicks": 100,
    "spend": 23470,
    "conversions": 24,
    "status": "PAUSED",
    "spend_too_high": "false"
  }
]
 

Video Example

Did this answer your question?
😞
😐
🤩

Last updated on June 21, 2023