Inline functions
Inline functions overviewCopy
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.
Creating inline functionsCopy
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 / chaining inline functionsCopy
For powerful functionality and flexibility, it is possible to chain / combine function calls in a single expression.
A combined function call would look something like:
isBefore(addMonths($.steps.object-helpers-1.result.registered_date, 6), addDays(now("UTC", "yyyy-MM-dd"), 21))
This combined function combines multiple date functions and returns true or false, so could be used directly in a boolean step:
Note that all functions are currently returned stringified, and so in this example you would need to check for a string of "true" rather than an actual boolean
A combined date function call like this would negate the need for multiple use of the date / time helpers connector:
The inline functions editorCopy
To use inline functions for any string-based field in the connector properties panel, select the function input type from the drop-down:
Then when using the editor you can use =
to search for functions by name and description
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:
Setting defaults via config (for date formatting etc.)Copy
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
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:
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 Copy
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:
You may need to subsequently edit for correct jsonpath etc.
stringFunctionsCopy
addBusinessDaysCopy
Adds a specified number of business days to a date
Example inputs | Example outputs |
---|---|
|
|
|
|
addDaysCopy
Adds a specified number of days to a date
Example inputs | Example outputs |
---|---|
|
|
addHoursCopy
Adds a specified number of hours to a date
Example inputs | Example outputs |
---|---|
|
|
addMinutesCopy
Adds a specified number of minutes to a date
Example inputs | Example outputs |
---|---|
|
|
addMonthsCopy
Adds a specified number of months to a date
Example inputs | Example outputs |
---|---|
|
|
addSecondsCopy
Adds a specified number of seconds to a date
Example inputs | Example outputs |
---|---|
|
|
addWeeksCopy
Adds a specified number of weeks to a date
Example inputs | Example outputs |
---|---|
|
|
addYearsCopy
Adds a specified number of years to a date
Example inputs | Example outputs |
---|---|
|
|
camelCaseCopy
Converts a string to camelCase
Example inputs | Example outputs |
---|---|
|
|
|
|
concatCopy
Concatenates two strings
Example inputs | Example outputs |
---|---|
|
|
|
|
formatDateCopy
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 |
---|---|
|
|
|
|
ifCopy
Returns one of two values based on a condition
Example inputs | Example outputs |
---|---|
|
|
|
|
|
|
kebabCaseCopy
Converts a string to kebab-case
Example inputs | Example outputs |
---|---|
|
|
|
|
lowerCaseCopy
Converts a string to lowercase
Example inputs | Example outputs |
---|---|
|
|
|
|
nowCopy
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 |
---|---|
|
|
|
|
parseDateCopy
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 |
---|---|
|
|
pascalCaseCopy
Converts a string to PascalCase (upperCamelCase, studlyCase)
Example inputs | Example outputs |
---|---|
|
|
|
|
removeSpecialCharactersCopy
Removes special characters from a string, keeping only letters and digits
Example inputs | Example outputs |
---|---|
|
|
|
|
replaceCopy
Replaces occurrences of a substring with another string
Example inputs | Example outputs |
---|---|
|
|
|
|
snakeCaseCopy
Converts a string to snake_case
Example inputs | Example outputs |
---|---|
|
|
|
|
substringCopy
Extracts a substring from a string
Example inputs | Example outputs |
---|---|
|
|
|
|
subtractBusinessDaysCopy
Subtracts a specified number of business days from a date
Example inputs | Example outputs |
---|---|
|
|
|
|
subtractDaysCopy
Subtracts a specified number of days from a date
Example inputs | Example outputs |
---|---|
|
|
subtractHoursCopy
Subtracts a specified number of hours from a date
Example inputs | Example outputs |
---|---|
|
|
subtractMinutesCopy
Subtracts a specified number of minutes from a date
Example inputs | Example outputs |
---|---|
|
|
subtractMonthsCopy
Subtracts a specified number of months to a date
Example inputs | Example outputs |
---|---|
|
|
subtractSecondsCopy
Subtracts a specified number of seconds from a date
Example inputs | Example outputs |
---|---|
|
|
subtractWeeksCopy
Subtracts a specified number of weeks from a date
Example inputs | Example outputs |
---|---|
|
|
subtractYearsCopy
Subtracts a specified number of years to a date
Example inputs | Example outputs |
---|---|
|
|
toStringCopy
Converts a value into a string
Example inputs | Example outputs |
---|---|
|
|
|
|
trimCopy
Trims whitespace from both ends of a string
Example inputs | Example outputs |
---|---|
|
|
|
|
upperCaseCopy
Converts a string to UPPERCASE
Example inputs | Example outputs |
---|---|
|
|
|
|
numberFunctionsCopy
absCopy
Returns the absolute value of a number
Example inputs | Example outputs |
---|---|
|
|
|
|
addCopy
Adds two numbers (sum)
Example inputs | Example outputs |
---|---|
|
|
|
|
ceilCopy
Returns the smallest integer greater than or equal to a number
Example inputs | Example outputs |
---|---|
|
|
|
|
divideCopy
Divides the first number by the second number
Example inputs | Example outputs |
---|---|
|
|
|
|
floorCopy
Returns the largest integer less than or equal to a number
Example inputs | Example outputs |
---|---|
|
|
|
|
ifCopy
Returns one of two values based on a condition
Example inputs | Example outputs |
---|---|
|
|
|
|
lengthCopy
Calculates the length of a string (size)
Example inputs | Example outputs |
---|---|
|
|
|
|
logCopy
Returns the natural logarithm (base e) of a number
Example inputs | Example outputs |
---|---|
|
|
|
|
log10Copy
Returns the base 10 logarithm of a number
Example inputs | Example outputs |
---|---|
|
|
|
|
modCopy
Calculates the remainder of the division of two numbers
Example inputs | Example outputs |
---|---|
|
|
|
|
multiplyCopy
Multiplies two numbers (product, times)
Example inputs | Example outputs |
---|---|
|
|
|
|
powCopy
Raises a number to the power of another number
Example inputs | Example outputs |
---|---|
|
|
|
|
roundCopy
Rounds a number to the nearest integer
Example inputs | Example outputs |
---|---|
|
|
|
|
sqrtCopy
Returns the square root of a number
Example inputs | Example outputs |
---|---|
|
|
|
|
subtractCopy
Subtracts the second number from the first number (minus, difference)
Example inputs | Example outputs |
---|---|
|
|
|
|
timestampInMillisecondsCopy
Returns the current timestamp in milliseconds since the epoch
Example inputs | Example outputs |
---|---|
|
|
timestampInSecondsCopy
Returns the current timestamp in seconds since the epoch
Example inputs | Example outputs |
---|---|
|
|
toNumberCopy
Converts a string to a number
Example inputs | Example outputs |
---|---|
|
|
|
|
booleanFunctionsCopy
andCopy
Performs logical AND operation on two boolean values
Example inputs | Example outputs |
---|---|
|
|
|
|
containsCopy
Checks if a string contains another string
Example inputs | Example outputs |
---|---|
|
|
|
|
endsWithCopy
Checks if a string ends with another string
Example inputs | Example outputs |
---|---|
|
|
|
|
eqCopy
Checks if two values are equal (equals)
Example inputs | Example outputs |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
greaterThanCopy
Checks if the first number is greater than the second number
Example inputs | Example outputs |
---|---|
|
|
|
|
|
|
ifCopy
Returns one of two values based on a condition
Example inputs | Example outputs |
---|---|
|
|
|
|
isAfterCopy
Checks if the first date is after the second date
Example inputs | Example outputs |
---|---|
|
|
|
|
isBeforeCopy
Checks if the first date is before the second date
Example inputs | Example outputs |
---|---|
|
|
|
|
isBlankCopy
Checks if a string is blank (empty or contains only whitespace)
Example inputs | Example outputs |
---|---|
|
|
|
|
|
|
isEmptyCopy
Checks if a string is empty
Example inputs | Example outputs |
---|---|
|
|
|
|
|
|
isValidDateCopy
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 |
---|---|
|
|
|
|
notCopy
Performs logical NOT operation on a boolean value
Example inputs | Example outputs |
---|---|
|
|
|
|
orCopy
Performs logical OR operation on two boolean values
Example inputs | Example outputs |
---|---|
|
|
|
|
propertyExistsCopy
Checks if a property exists
Example inputs | Example outputs |
---|---|
|
|
smallerThanCopy
Checks if the first number is smaller than the second number
Example inputs | Example outputs |
---|---|
|
|
|
|
|
|
startsWithCopy
Checks if a string starts with another string
Example inputs | Example outputs |
---|---|
|
|
|
|
toBooleanCopy
Converts a string to a boolean value
Example inputs | Example outputs |
---|---|
|
|
|
|