Functions in Tines explained

Best practice advice from the team at Tines for getting started with functions.

Ruairí Galavan avatar
Written by Ruairí Galavan
Updated over a week ago

What is a function?

A function is a reusable instruction that you can use to perform certain tasks in Tines. You can tell Tines to do a whole range of things using functions, such as edit or transform data. Functions can also tell you things about data, giving you values like counts, dates, times, and others. Functions are a critical component of what makes Tines so powerful - allowing you to automate specific tasks with any set of data.

The best thing about Functions in Tines? If you know how to use Functions in Excel, you already know how to use Functions in Tines.

An example of a function

Each function has a name denoted in CAPSLOCK. A simple example of a function is the function JOIN.

Let's say you have a list of items and want to join them together in a single string, you would use the JOIN function. This function combines the elements in an array into a single text value. So, if you had an array that had four items in it, north, south, east and west, it might look like this:

The JOIN function would join all those items together into a single string. The formula syntax for the JOIN function looks like this: JOIN(array, join_text). To do this, you would add an Event Transform action containing that formula to your story.

Then, in the JOIN event Transform action, enter JOIN(my_action.message, “ ”) in the payload of the build pane. When you run the story, the output would be "north south east west".

Best practice advice from the Tines team for using Functions

Here at Tines we use functions a lot. So, to help you get up to speed with Functions as quickly as possible, we’re sharing our best practice advice with you.

First, let Eoin show you around

Eoin Magner is a customer success Engineer at Tines. In this 3-minute video below he shares his top tips for getting started with functions in Tines.

Start simple

A great place to start is our functions library, here. But, it’s a very long list and is most useful if you know what you’re looking for. So here’s a short list of just some of the useful (but also easiest the get started with) functions to get quick results from:

  • SIZE: This function returns the number of characters in text or the number of elements in an array. For example if you had an array with four elements, the SIZE function would return an output of 4.

  • PLUS: This function adds a number to another number. For example, if you had the number 6 in a message, you could use the PLUS function to add 2 to it, with an output of 8.

  • DAY: The function DAY returns the day of the month for the specified date. The accepted Format is `year-month-day (year/month/day)`. So for example, if you use the accepted format (e.g., 2022-03-19) you would get an output of 19.

  • DOWNCASE: This function turns any uppercase character in text to lowercase. For example, it would turn ‘Hello World’ into `hello world`.

  • JOIN: As we saw in the example above, this function combines the elements in an array into a single text value using the argument as a separator.

  • SORT: This function sorts elements in an array by a property of an element in the array. For example if you had an array of users, and each had the following elements: First Name, Surname, Id, Job, you could use SORT to order the list of users by surname.

  • DEFAULT: This function allows you to specify a fallback in case a value doesn’t exist. For example, if you wanted to say Hi "first name" but we don't have a first name, we can say "hi there" where the fallback is "there"

  • INCLUDES: This function returns TRUE if the target (which can be text, an object, or an array) includes the value, otherwise it will return as FALSE. For example if you had a target with a value of “Hello world” and you used the formula INCLUDES(my_action.value, "world"), it would return an output of TRUE.

Make use of example blocks

Our next piece of advice is to familiarize yourself with the usage examples and in particular, the sample actions. You can easily copy paste these from the functions library into your own story. It’s a serious time saver!

Copy these into your own story to see and understand how it works there and then. Now you’ve got a great starting point to input your own specifics in place of the example content.

Leverage the highest-impact functions

There are hundreds of predefined functions in Tines, but some are more valuable than others. Where some are highly specific, others provide greater utility. Below is our list of the most valuable ones. These can also be some of the trickier ones to get working, so we recommend starting simple with the list above in #1.

  • MAP: The MAP function creates an array by extracting the values of a named property from an array of objects.

  • LAMBDA: The LAMBDA function is basically a custom function, where you can create your own function to perform a specific task. LAMBDA can be used as a standalone function or within other functions, such as FILTER, to perform calculations on each item in an array.

  • MAP_LAMBDA: Now that we know MAP, and now that we know LAMBDA, it’s easiest to think of MAP_LAMBDA as a combination of these two. Where MAP iterates over an array, and LAMBDA gives us a reusable function, MAP_LAMBDA iterates over the array and performs an operation defined in the LAMBDA on each entry.

  • WHERE: This function will select all the elements in an array where the key has the given value.

  • FILTER: Filter is a function that takes either an array or an object, along with either a lambda function or an array of values to retain. When provided with an array, it returns a new array containing only the values that satisfy the condition specified by the lambda function or are included in the array of values to retain. When given an object, it returns a new object containing only the key-value pairs where the values satisfy the condition specified by the lambda function or are included in the array of values to retain.

  • REJECT: This function lets you remove specified objects, lists, or arrays. For example, if you had an array 1,2,3,4,5,6,7,8,9,10, you could use REJECT(my_array, ARRAY(2, 4, 6, 8, 10)) which would give you an output of 1,3,5,7,9.

  • REDUCE: This function turns an array into a single value. For example, if you had a list of numbers, you can add them all together, multiply them, or find the maximum number. For example, if you had an array of numbers, you could iterate through the array, adding on the current number to the total of all previously summed numbers.

Did this answer your question?