Mapping Data

Inline functions

Inline functions

Inline functions overview

Tray's inline functions feature allows you to perform data transformations directly on data that is being pulled into your workflow steps. This can bring extra functionality, flexibility and efficiency to your workflows. One of the main benefits is that it can simplify tasks which would normally require multiple core / helper steps in combination with booleans and branches, thus leading to overly-complex workflows.

Note that all functions are currently returned stringified, and so in the examples provided below you would need to check for a string of "true" rather than an actual boolean.


Creating inline functions

Inline functions can be used both as single function calls, and as combined function calls which mix multiple functions.

  • A function call must use the format of functionName(parameter1, parameter2)
  • The parameters of each function are contained within ( )
  • Parameters can be hardcoded or can use jsonpaths to reference both data from previous steps via $.steps. and project config variables via $.config.
  • Functions can contain 1 or more parameters A single function call would look something like: formatDate("04/09/2023", "yyyy-MM-dd") This could be used to e.g. format a date directly in the relevant properties panel field when using the date filter option in an operation such as Salesforce's 'Find records':

Please see the Setting defaults via config section below for guidance on standardized use of timezones and date formats


Combining multiple Inline Functions

For powerful functionality and flexibility, it is possible to chain combine function calls in a single expression. A chained function call would look something like: isBefore(addMonths($.steps.object-helpers-1.result.registered_date, 6), addDays(now("UTC", "yyyy-MM-dd"), 21)) This chained function combines multiple date functions and returns true or false, so could be used directly in a boolean step: inline-functions-combined-date-functions A chained date function call like this would negate the need for multiple use of the date / time helpers connector: inline-functions-date-time-helpers

The inline functions editor

To use inline functions for any string-based field in the connector properties panel, select the function input type from the drop-down: select-f-x-dropdown Then when using the editor you can use = to search for functions by name and description inline-functions-search-function And you can use / to search for mapped data (via jsonpaths) from previous workflow steps ($.steps.) and project config ($.config.) to add as dynamic arguments: inline-functions-search-for-jsonpath

Setting defaults via config (for date formatting etc.)

To standardize how you work with dates (and avoid having to repeatedly enter formatting parameters), you can make use of project config to set your timezone and also to set the formats that are required to work with particular services. For example you could set the following project config to work with Salesforce:

  • date_format = yyyy-MM-dd
  • date_time_format = yyyy-MM-dd'T'HH:mm:ssZ
  • timezone = PST inline-functions-config-defaults This allows us to flexibly adapt to the Valid Date and DateTime Formats of Salesforce whereby some endpoints require date in Date format and some require it in DateTime format. The project config can then be used in a function such as formatDate($.steps.object-helpers-1.result.launch_date, $.config.date_format) when making calls to the service: inline-function-format-date-for-salesforce You could also use project config to build your own standarized 'TODAY' function whereby using a timezone and date format (i.e. not date/time) as parameters for the 'now' function will return today's date: now($.config.timezone, $.config.date_format)

Getting Merlin search to build functions

Merlin search (the docs knowledge agent) can be used to build complex combined functions for you. You can ask questions in the following manner: Using tray's inline functions feature *only* (stringFunctions, numberFunctions and booleanFunctions) how could I create a URL slug from a title by replacing spaces and underscores with hyphens and converting it to lowercase? Merlin should then return a function which you can directly copy and paste into the inline functions editor: ask-merlin-inline-functions You may need to subsequently edit for correct jsonpath etc.

stringFunctions

addBusinessDays

Adds a specified number of business days to a date

Example inputsExample outputs
addBusinessDays("2024-01-01T00:00:00", 1)"2024-01-02T00:00:00+0000"
addBusinessDays("2024-01-01T00:00:00", 5)"2024-01-08T00:00:00+0000"

addDays

Adds a specified number of days to a date

Example inputsExample outputs
addDays("2024-01-01T00:00:00", 10)"2024-01-11T00:00:00+0000"

addHours

Adds a specified number of hours to a date

Example inputsExample outputs
addHours("2024-01-01T00:00:00", 1)"2024-01-01T01:00:00+0000"

addMinutes

Adds a specified number of minutes to a date

Example inputsExample outputs
addMinutes("2024-01-01T00:00:00", 1)"2024-01-01T00:01:00+0000"

addMonths

Adds a specified number of months to a date

Example inputsExample outputs
addMonths("2024-01-01T00:00:00", 2)"2024-03-01T00:00:00+0000"

addSeconds

Adds a specified number of seconds to a date

Example inputsExample outputs
addSeconds("2024-01-01T00:00:00", 1)"2024-01-01T00:00:01+0000"

addWeeks

Adds a specified number of weeks to a date

Example inputsExample outputs
addWeeks("2024-01-01T00:00:00", 2)"2024-01-15T00:00:00+0000"

addYears

Adds a specified number of years to a date

Example inputsExample outputs
addYears("2024-01-01T00:00:00", 2)"2026-01-01T00:00:00+0000

camelCase

Converts a string to camelCase

Example inputsExample outputs
camelCase("hello world")"helloWorld"
camelCase("foo_bar")"fooBar"

concat

Concatenates two strings

Example inputsExample outputs
concat("Hello, ", "world!")"Hello, world!"
concat("foo", "bar")"foobar"

formatDate

Formats a date string according to the specified format. The input date must be valid according to the isValidDate function Valid patterns can be constructed using the following symbols:

  • YY - short year: 24
  • YYYY - long year: 2024
  • Q - quarter: 1
  • M - month: 5
  • MM - month: 05
  • MMM - month: Feb
  • MMMM - month: February
  • W - week of the year: 6
  • WW - week of the year: 06
  • D - day of month: 6
  • DD - day of month: 06
  • DDD - day of year: 39
  • DDDD - day of year: 039
  • d - day of the week: 1
  • dd - day of the week: Mon
  • ddd - day of the week: Mon
  • dddd - day of the week: Monday
  • a - am/pm: am
  • H - hour (0-23): 1
  • HH - hour (0-23): 01
  • h - hour (1-12): 1
  • hh - hour (1-12): 01
  • k - hour (1-24): 1
  • kk - hour (1-24): 01
  • m - minute: 2
  • mm - minute: 02
  • s - second: 3
  • ss - second: 03
  • S - millisecond: 4
  • SS - millisecond: 40
  • SSS - millisecond: 400
  • Z - zone offset: +00:00
  • ZZ - zone offset: +0000
  • T - The character T
  • 'string' - '' can be used to introduce any string in the formatted value

As an alternative to composing a format with the above some special formats can be specified:

  • salesforce_date_time - this is the date time format used by Salesforce
  • salesforce_date - this is the date format used by Salesforce | Example inputs | Example outputs | | --- | --- | | formatDate("2024-05-16", "DD/MM/YYYY") | "16/05/2024" | | formatDate("2024-05-16T12:30:00", "YYYY-MM-DD HH:mm") | "2024-05-16 12:30" |

if

Returns one of two values based on a condition

Example inputsExample outputs
if(true, "yes", "no")"yes"
if(false, "yes", "no")"no"
if(null, "yes", "no")"no"

kebabCase

Converts a string to kebab-case

Example inputsExample outputs
kebabCase("hello world")"hello-world"
kebabCase("fooBar")"foo-bar"

lowerCase

Converts a string to lowercase

Example inputsExample outputs
lowerCase("HELLO")"hello"
lowerCase("Test")"test"

now

Returns the current date and time formatted according to the specified format and time zone Valid patterns can be constructed using the following symbols:

  • YY - short year: 24
  • YYYY - long year: 2024
  • Q - quarter: 1
  • M - month: 5
  • MM - month: 05
  • MMM - month: Feb
  • MMMM - month: February
  • W - week of the year: 6
  • WW - week of the year: 06
  • D - day of month: 6
  • DD - day of month: 06
  • DDD - day of year: 39
  • DDDD - day of year: 039
  • d - day of the week: 1
  • dd - day of the week: Mon
  • ddd - day of the week: Mon
  • dddd - day of the week: Monday
  • a - am/pm: am
  • H - hour (0-23): 1
  • HH - hour (0-23): 01
  • h - hour (1-12): 1
  • hh - hour (1-12): 01
  • k - hour (1-24): 1
  • kk - hour (1-24): 01
  • m - minute: 2
  • mm - minute: 02
  • s - second: 3
  • ss - second: 03
  • S - millisecond: 4
  • SS - millisecond: 40
  • SSS - millisecond: 400
  • Z - zone offset: +00:00
  • ZZ - zone offset: +0000
  • T - The character T
  • 'string' - '' can be used to introduce any string in the formatted value

As an alternative to composing a format with the above some special formats can be specified:

  • salesforce_date_time - this is the date time format used by Salesforce
  • salesforce_date - this is the date format used by Salesforce | Example inputs | Example outputs | | --- | --- | | now("UTC", "YYYY-MM-DD HH:mm:ss") | "2024-05-16 12:30:45" | | now("Europe/London", "DD/MM/YYYY HH:mm") | "16/05/2024 13:30" |

parseDate

Parses a date according to the specified format and returns it formatted using the default format YYYY-MM-DDTHH:mm:ss.SSSZZ (Missing info will be filled with defaults) Valid patterns can be constructed using the following symbols:

  • YY - short year: 24
  • YYYY - long year: 2024
  • Q - quarter: 1
  • M - month: 5
  • MM - month: 05
  • MMM - month: Feb
  • MMMM - month: February
  • W - week of the year: 6
  • WW - week of the year: 06
  • D - day of month: 6
  • DD - day of month: 06
  • DDD - day of year: 39
  • DDDD - day of year: 039
  • d - day of the week: 1
  • dd - day of the week: Mon
  • ddd - day of the week: Mon
  • dddd - day of the week: Monday
  • a - am/pm: am
  • H - hour (0-23): 1
  • HH - hour (0-23): 01
  • h - hour (1-12): 1
  • hh - hour (1-12): 01
  • k - hour (1-24): 1
  • kk - hour (1-24): 01
  • m - minute: 2
  • mm - minute: 02
  • s - second: 3
  • ss - second: 03
  • S - millisecond: 4
  • SS - millisecond: 40
  • SSS - millisecond: 400
  • Z - zone offset: +00:00
  • ZZ - zone offset: +0000
  • T - The character T
  • 'string' - '' can be used to introduce any string in the formatted value

As an alternative to composing a format with the above some special formats can be specified:

  • salesforce_date_time - this is the date time format used by Salesforce
  • salesforce_date - this is the date format used by Salesforce | Example inputs | Example outputs | | --- | --- | | parseDate("07-22-23", "MM-DD-YY") | "2023-07-22 00:00" |

pascalCase

Converts a string to PascalCase (upperCamelCase, studlyCase)

Example inputsExample outputs
pascalCase("hello world")"HelloWorld"
pascalCase("foo_bar")"FooBar"

removeSpecialCharacters

Removes special characters from a string, keeping only letters and digits

Example inputsExample outputs
removeSpecialCharacters("hello@world!")"helloworld"
removeSpecialCharacters("foo_bar123")"foobar123"

replace

Replaces occurrences of a substring with another string

Example inputsExample outputs
replace("hello world", "world", "scala")"hello scala"
replace("abcabc", "a", "x")"xbcxbc"

snakeCase

Converts a string to snake_case

Example inputsExample outputs
snakeCase("hello world")"hello_world"
snakeCase("fooBar")"foo_bar"

substring

Extracts a substring from a string

Example inputsExample outputs
substring("hello", 0, 2)"he"
substring("world", 1, 4)"orl"

subtractBusinessDays

Subtracts a specified number of business days from a date

Example inputsExample outputs
subtractBusinessDays("2024-01-01T00:00:00", 1)"2023-12-31T00:00:00+0000"
subtractBusinessDays("2024-01-01T00:00:00", 5)"2023-12-25T00:00:00+0000"

subtractDays

Subtracts a specified number of days from a date

Example inputsExample outputs
subtractDays("2024-01-01T00:00:00", 10)"2023-12-22T00:00:00+0000"

subtractHours

Subtracts a specified number of hours from a date

Example inputsExample outputs
subtractHours("2024-01-01T00:00:00", 1)"2023-12-31T23:00:00+0000"

subtractMinutes

Subtracts a specified number of minutes from a date

Example inputsExample outputs
subtractMinutes("2024-01-01T00:00:00", 1)"2023-12-31T23:59:00+0000"

subtractMonths

Subtracts a specified number of months to a date

Example inputsExample outputs
subtractMonths("2024-01-01T00:00:00", 2)"2023-11-01T00:00:00+0000"

subtractSeconds

Subtracts a specified number of seconds from a date

Example inputsExample outputs
subtractSeconds("2024-01-01T00:00:00", 1)"2023-12-31T23:59:59+0000"

subtractWeeks

Subtracts a specified number of weeks from a date

Example inputsExample outputs
subtractWeeks("2024-01-01T00:00:00", 2)"2023-12-18T00:00:00+0000"

subtractYears

Subtracts a specified number of years to a date

Example inputsExample outputs
subtractYears("2024-01-01T00:00:00", 2)"2022-01-01T00:00:00+0000

toString

Converts a value into a string

Example inputsExample outputs
toString(1)"1"
toString(true)"true"

trim

Trims whitespace from both ends of a string

Example inputsExample outputs
trim(" hello ")"hello"
trim("test")"test"

upperCase

Converts a string to UPPERCASE

Example inputsExample outputs
upperCase("hello")"HELLO"
upperCase("Test")"TEST"

numberFunctions

abs

Returns the absolute value of a number

Example inputsExample outputs
abs(-5)5
abs(5)5

add

Adds two numbers (sum)

Example inputsExample outputs
add(1, 2)3
add(3.5, 2.5)6

ceil

Returns the smallest integer greater than or equal to a number

Example inputsExample outputs
ceil(4.2)5
ceil(-4.8)-4

divide

Divides the first number by the second number

Example inputsExample outputs
divide(6, 2)3
divide(7, 2)3.5

floor

Returns the largest integer less than or equal to a number

Example inputsExample outputs
floor(4.8)4
floor(-4.2)-5

if

Returns one of two values based on a condition

Example inputsExample outputs
if(true, 1, 2)1
if(false, 1, 2)2

indexOf

Finds the index of a substring in a string

Example inputsExample outputs
indexOf("hello", "ell")1
indexOf("world", "ell")-1

length

Calculates the length of a string (size)

Example inputsExample outputs
length("Hello")5
length("")0

log

Returns the natural logarithm (base e) of a number

Example inputsExample outputs
log(1)0
log(2)0.6931471805599453

log10

Returns the base 10 logarithm of a number

Example inputsExample outputs
log10(1)0
log10(10)1

mod

Calculates the remainder of the division of two numbers

Example inputsExample outputs
mod(5, 2)1
mod(6, 3)0

multiply

Multiplies two numbers (product, times)

Example inputsExample outputs
multiply(2, 3)6
multiply(3.5, 2)7

pow

Raises a number to the power of another number

Example inputsExample outputs
pow(2, 3)8
pow(4, 0.5)2

round

Rounds a number to the nearest integer

Example inputsExample outputs
round(4.5)5
round(4.4)4

sqrt

Returns the square root of a number

Example inputsExample outputs
sqrt(4)2
sqrt(9)3

subtract

Subtracts the second number from the first number (minus, difference)

Example inputsExample outputs
subtract(5, 3)2
subtract(3.5, 2.5)1

timestampInMilliseconds

Returns the current timestamp in milliseconds since the epoch

Example inputsExample outputs
timestampInMilliseconds()1621265400123

timestampInSeconds

Returns the current timestamp in seconds since the epoch

Example inputsExample outputs
timestampInSeconds()1621265400

toNumber

Converts a string to a number

Example inputsExample outputs
toNumber("123")123
toNumber("45.67")45.67

booleanFunctions

and

Performs logical AND operation on two boolean values

Example inputsExample outputs
and(true, false)false
and(true, true)true

contains

Checks if a string contains another string

Example inputsExample outputs
contains("hello", "ell")true
contains("world", "ell")false

endsWith

Checks if a string ends with another string

Example inputsExample outputs
endsWith("hello", "lo")true
endsWith("world", "lo")false

eq

Checks if two values are equal (equals)

Example inputsExample outputs
eq(1, 1)true
eq(1, 2)false
eq("aa", "aa")true
eq("aa", "a")false
eq(false, false)true
eq(true, false)false
eq(0, false)false

greaterThan

Checks if the first number is greater than the second number

Example inputsExample outputs
greaterThan(5, 3)true
greaterThan(3, 5)false
greaterThan(5, 5)false

if

Returns one of two values based on a condition

Example inputsExample outputs
if(true, true, false)true
if(false, true, false)false

isAfter

Checks if the first date is after the second date

Example inputsExample outputs
isAfter("2024-05-16", "2024-05-17")false
isAfter("2024-05-17", "2024-05-16")true

isBefore

Checks if the first date is before the second date

Example inputsExample outputs
isBefore("2024-05-16", "2024-05-17")true
isBefore("2024-05-16", "2024-05-16")false

isBlank

Checks if a string is blank (empty or contains only whitespace)

Example inputsExample outputs
isBlank("hello")false
isBlank(" ")true
isBlank("")true

isEmpty

Checks if a string is empty

Example inputsExample outputs
isEmpty("hello")false
isEmpty(" ")false
isEmpty("")true

isValidDate

Checks if a string is a valid date according to the accepted formats. A valid date can be used on all the functions accepting a date as parameter. The following is a list of examples of valid dates; other formats can be supported via the parseDate function:

  • "2024-01-22T23:04:05.000+0000"
  • "2024-01-22T23:04:05.000Z"
  • "2024-01-22T23:04:05.000+00:00"
  • "2024-01-22T23:04:05.000"
  • "2024-01-22T23:04:05+0000"
  • "2024-01-22T23:04:05Z"
  • "2024-01-22T23:04:05+00:00"
  • "2024-01-22T23:04:05"
  • "2024-01-22 23:04:05.000 +0000"
  • "2024-01-22 23:04:05.000 Z"
  • "2024-01-22 23:04:05.000 +00:00"
  • "2024-01-22 23:04:05.000"
  • "2024-01-22 23:04:05 +0000"
  • "2024-01-22 23:04:05 Z"
  • "2024-01-22 23:04:05 +00:00"
  • "2024-01-22 23:04:05"
  • "2024-01-22 23:04"
  • "2024-01-22"
  • "22-01-2024"
  • "22/01/2024"
  • "22/01/24"
  • "01-22-2024"
  • "01/22/2024"
  • "01/22/06" | Example inputs | Example outputs | | --- | --- | | isValidDate("2024-05-16") | true | | isValidDate("invalid-date") | false |

not

Performs logical NOT operation on a boolean value

Example inputsExample outputs
not(true)false
not(false)true

or

Performs logical OR operation on two boolean values

Example inputsExample outputs
or(true, false)true
or(false, false)false

propertyExists

Checks if a property exists

Example inputsExample outputs
propertyExists($.steps.step-1.field)true

smallerThan

Checks if the first number is smaller than the second number

Example inputsExample outputs
smallerThan(3, 5)true
smallerThan(5, 3)false
smallerThan(3, 3)false

startsWith

Checks if a string starts with another string

Example inputsExample outputs
startsWith("hello", "he")true
startsWith("world", "he")false

toBoolean

Converts a string to a boolean value

Example inputsExample outputs
toBoolean("true")true
toBoolean("false")false

Was this page helpful?