Advanced Formula Examples (duplicate)

For our advanced users 

Familiarize yourself with formulas by practicing these common applications in your Tines Story.

Get the current date and time in yyyymmdd format

DATE("now", "%Y%m%d")

Get time 24hrs ago

DATE(DATE("now", "%s") - 24 * 60 * 60, "%Y-%m-%dT%l:%M:%S%z")

Get the Size of an Array from an Incoming Event

SIZE(my_array)

Get the size of an ARRAY and multiply by 10

SIZE(my_array) * 10

Select all the elements in an array where the key has the given value

Input:

[
  {
    "color": "red",
    "index": "1"
  },
  {
    "color": "blue",
    "index": "2"
  },
  {
    "color": "green",
    "index": "3"
  }
]

Formula:

WHERE(my_array, "index", "1")

Output:

[{"color":"red","index":"1"}]

Select all the elements in an array that REGEX_MATCH the string "r"

Input:

[
  "red",
  "blue",
  "green"
]

Formula:

FILTER(my_array, LAMBDA(element, MATCH(element, "r")))

Output:

["red","green"]

Get the difference between 2 arrays, i.e. get elements from array_two that are not present in array_one

Input:

array_one = [
  "dog",
  "cat",
  "turtle",
  "dinosaur",
  "lizard",
  "chicken",
  "koala"
]
array_two = [
  "cat",
  "elephant",
  "giraffe",
  "penguin",
  "tiger",
  "koala"
]

Formula:

FILTER(array_two, LAMBDA(arr_two_elem, NOT(INCLUDES(array_one, arr_two_elem))))

Output:

[
  "elephant",
  "giraffe",
  "penguin",
  "tiger"
]

Construct an array of objects from an input array

Input:

[
  "foo@tines.com", 
  "bar@tines.com"
]

Formula:

MAP_LAMBDA(email_array, LAMBDA(elem, OBJECT(\"email_address\", OBJECT(\"address\", elem))))

Output:

[
  {
    "email_address": {
      "address": "foo@tines.io"
    }
  },
  {
    "email_address": {
      "address": "bar@tines.io"
    }
  }
]

Multiply a number in an incoming event by 10

my_number * 10

Generate a random number between 1 and 10

RANDOM(1, 10)
Was this helpful?