Inline functions

                                                  Inline functions overview
                                                  Copy

                                                  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 functions
                                                  Copy

                                                  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 functions
                                                  Copy

                                                  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 editor
                                                  Copy

                                                  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.

                                                  stringFunctions
                                                  Copy

                                                  addBusinessDays
                                                  Copy

                                                  Adds a specified number of business days to a date

                                                  Example inputs

                                                  Example 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
                                                  Copy

                                                  Adds a specified number of days to a date

                                                  Example inputs

                                                  Example outputs

                                                  addDays("2024-01-01T00:00:00", 10)

                                                  "2024-01-11T00:00:00+0000"

                                                  addHours
                                                  Copy

                                                  Adds a specified number of hours to a date

                                                  Example inputs

                                                  Example outputs

                                                  addHours("2024-01-01T00:00:00", 1)

                                                  "2024-01-01T01:00:00+0000"

                                                  addMinutes
                                                  Copy

                                                  Adds a specified number of minutes to a date

                                                  Example inputs

                                                  Example outputs

                                                  addMinutes("2024-01-01T00:00:00", 1)

                                                  "2024-01-01T00:01:00+0000"

                                                  addMonths
                                                  Copy

                                                  Adds a specified number of months to a date

                                                  Example inputs

                                                  Example outputs

                                                  addMonths("2024-01-01T00:00:00", 2)

                                                  "2024-03-01T00:00:00+0000"

                                                  addSeconds
                                                  Copy

                                                  Adds a specified number of seconds to a date

                                                  Example inputs

                                                  Example outputs

                                                  addSeconds("2024-01-01T00:00:00", 1)

                                                  "2024-01-01T00:00:01+0000"

                                                  addWeeks
                                                  Copy

                                                  Adds a specified number of weeks to a date

                                                  Example inputs

                                                  Example outputs

                                                  addWeeks("2024-01-01T00:00:00", 2)

                                                  "2024-01-15T00:00:00+0000"

                                                  addYears
                                                  Copy

                                                  Adds a specified number of years to a date

                                                  Example inputs

                                                  Example outputs

                                                  addYears("2024-01-01T00:00:00", 2)

                                                  "2026-01-01T00:00:00+0000

                                                  camelCase
                                                  Copy

                                                  Converts a string to camelCase

                                                  Example inputs

                                                  Example outputs

                                                  camelCase("hello world")

                                                  "helloWorld"

                                                  camelCase("foo_bar")

                                                  "fooBar"

                                                  concat
                                                  Copy

                                                  Concatenates two strings

                                                  Example inputs

                                                  Example outputs

                                                  concat("Hello, ", "world!")

                                                  "Hello, world!"

                                                  concat("foo", "bar")

                                                  "foobar"

                                                  formatDate
                                                  Copy

                                                  Formats a date string according to the specified format

                                                  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
                                                  Copy

                                                  Returns one of two values based on a condition

                                                  Example inputs

                                                  Example outputs

                                                  if(true, "yes", "no")

                                                  "yes"

                                                  if(false, "yes", "no")

                                                  "no"

                                                  if(null, "yes", "no")

                                                  "no"

                                                  kebabCase
                                                  Copy

                                                  Converts a string to kebab-case

                                                  Example inputs

                                                  Example outputs

                                                  kebabCase("hello world")

                                                  "hello-world"

                                                  kebabCase("fooBar")

                                                  "foo-bar"

                                                  lowerCase
                                                  Copy

                                                  Converts a string to lowercase

                                                  Example inputs

                                                  Example outputs

                                                  lowerCase("HELLO")

                                                  "hello"

                                                  lowerCase("Test")

                                                  "test"

                                                  now
                                                  Copy

                                                  Returns the current date and time formatted according to the specified format and time zone

                                                  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"

                                                  pascalCase
                                                  Copy

                                                  Converts a string to PascalCase (upperCamelCase, studlyCase)

                                                  Example inputs

                                                  Example outputs

                                                  pascalCase("hello world")

                                                  "HelloWorld"

                                                  pascalCase("foo_bar")

                                                  "FooBar"

                                                  removeSpecialCharacters
                                                  Copy

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

                                                  Example inputs

                                                  Example outputs

                                                  removeSpecialCharacters("hello@world!")

                                                  "helloworld"

                                                  removeSpecialCharacters("foo_bar123")

                                                  "foobar123"

                                                  replace
                                                  Copy

                                                  Replaces occurrences of a substring with another string

                                                  Example inputs

                                                  Example outputs

                                                  replace("hello world", "world", "scala")

                                                  "hello scala"

                                                  replace("abcabc", "a", "x")

                                                  "xbcxbc"

                                                  snakeCase
                                                  Copy

                                                  Converts a string to snake_case

                                                  Example inputs

                                                  Example outputs

                                                  snakeCase("hello world")

                                                  "hello_world"

                                                  snakeCase("fooBar")

                                                  "foo_bar"

                                                  substring
                                                  Copy

                                                  Extracts a substring from a string

                                                  Example inputs

                                                  Example outputs

                                                  substring("hello", 0, 2)

                                                  "he"

                                                  substring("world", 1, 4)

                                                  "orl"

                                                  toString
                                                  Copy

                                                  Converts a value into a string

                                                  Example inputs

                                                  Example outputs

                                                  toString(1)

                                                  "1"

                                                  toString(true)

                                                  "true"

                                                  trim
                                                  Copy

                                                  Trims whitespace from both ends of a string

                                                  Example inputs

                                                  Example outputs

                                                  trim(" hello ")

                                                  "hello"

                                                  trim("test")

                                                  "test"

                                                  upperCase
                                                  Copy

                                                  Converts a string to UPPERCASE

                                                  Example inputs

                                                  Example outputs

                                                  upperCase("hello")

                                                  "HELLO"

                                                  upperCase("Test")

                                                  "TEST"

                                                  numberFunctions
                                                  Copy

                                                  abs
                                                  Copy

                                                  Returns the absolute value of a number

                                                  Example inputs

                                                  Example outputs

                                                  abs(-5)

                                                  5

                                                  abs(5)

                                                  5

                                                  add
                                                  Copy

                                                  Adds two numbers (sum)

                                                  Example inputs

                                                  Example outputs

                                                  add(1, 2)

                                                  3

                                                  add(3.5, 2.5)

                                                  6

                                                  ceil
                                                  Copy

                                                  Returns the smallest integer greater than or equal to a number

                                                  Example inputs

                                                  Example outputs

                                                  ceil(4.2)

                                                  5

                                                  ceil(-4.8)

                                                  -4

                                                  divide
                                                  Copy

                                                  Divides the first number by the second number

                                                  Example inputs

                                                  Example outputs

                                                  divide(6, 2)

                                                  3

                                                  divide(7, 2)

                                                  3.5

                                                  floor
                                                  Copy

                                                  Returns the largest integer less than or equal to a number

                                                  Example inputs

                                                  Example outputs

                                                  floor(4.8)

                                                  4

                                                  floor(-4.2)

                                                  -5

                                                  if
                                                  Copy

                                                  Returns one of two values based on a condition

                                                  Example inputs

                                                  Example outputs

                                                  if(true, 1, 2)

                                                  1

                                                  if(false, 1, 2)

                                                  2

                                                  length
                                                  Copy

                                                  Calculates the length of a string (size)

                                                  Example inputs

                                                  Example outputs

                                                  length("Hello")

                                                  5

                                                  length("")

                                                  0

                                                  log
                                                  Copy

                                                  Returns the natural logarithm (base e) of a number

                                                  Example inputs

                                                  Example outputs

                                                  log(1)

                                                  0

                                                  log(2)

                                                  0.6931471805599453

                                                  log10
                                                  Copy

                                                  Returns the base 10 logarithm of a number

                                                  Example inputs

                                                  Example outputs

                                                  log10(1)

                                                  0

                                                  log10(10)

                                                  1

                                                  mod
                                                  Copy

                                                  Calculates the remainder of the division of two numbers

                                                  Example inputs

                                                  Example outputs

                                                  mod(5, 2)

                                                  1

                                                  mod(6, 3)

                                                  0

                                                  multiply
                                                  Copy

                                                  Multiplies two numbers (product, times)

                                                  Example inputs

                                                  Example outputs

                                                  multiply(2, 3)

                                                  6

                                                  multiply(3.5, 2)

                                                  7

                                                  pow
                                                  Copy

                                                  Raises a number to the power of another number

                                                  Example inputs

                                                  Example outputs

                                                  pow(2, 3)

                                                  8

                                                  pow(4, 0.5)

                                                  2

                                                  round
                                                  Copy

                                                  Rounds a number to the nearest integer

                                                  Example inputs

                                                  Example outputs

                                                  round(4.5)

                                                  5

                                                  round(4.4)

                                                  4

                                                  sqrt
                                                  Copy

                                                  Returns the square root of a number

                                                  Example inputs

                                                  Example outputs

                                                  sqrt(4)

                                                  2

                                                  sqrt(9)

                                                  3

                                                  subtract
                                                  Copy

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

                                                  Example inputs

                                                  Example outputs

                                                  subtract(5, 3)

                                                  2

                                                  subtract(3.5, 2.5)

                                                  1

                                                  timestampInMilliseconds
                                                  Copy

                                                  Returns the current timestamp in milliseconds since the epoch

                                                  Example inputs

                                                  Example outputs

                                                  timestampInMilliseconds()

                                                  1621265400123

                                                  timestampInSeconds
                                                  Copy

                                                  Returns the current timestamp in seconds since the epoch

                                                  Example inputs

                                                  Example outputs

                                                  timestampInSeconds()

                                                  1621265400

                                                  toNumber
                                                  Copy

                                                  Converts a string to a number

                                                  Example inputs

                                                  Example outputs

                                                  toNumber("123")

                                                  123

                                                  toNumber("45.67")

                                                  45.67

                                                  booleanFunctions
                                                  Copy

                                                  and
                                                  Copy

                                                  Performs logical AND operation on two boolean values

                                                  Example inputs

                                                  Example outputs

                                                  and(true, false)

                                                  false

                                                  and(true, true)

                                                  true

                                                  contains
                                                  Copy

                                                  Checks if a string contains another string

                                                  Example inputs

                                                  Example outputs

                                                  contains("hello", "ell")

                                                  true

                                                  contains("world", "ell")

                                                  false

                                                  endsWith
                                                  Copy

                                                  Checks if a string ends with another string

                                                  Example inputs

                                                  Example outputs

                                                  endsWith("hello", "lo")

                                                  true

                                                  endsWith("world", "lo")

                                                  false

                                                  eq
                                                  Copy

                                                  Checks if two values are equal (equals)

                                                  Example inputs

                                                  Example 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
                                                  Copy

                                                  Checks if the first number is greater than the second number

                                                  Example inputs

                                                  Example outputs

                                                  greaterThan(5, 3)

                                                  true

                                                  greaterThan(3, 5)

                                                  false

                                                  greaterThan(5, 5)

                                                  false

                                                  if
                                                  Copy

                                                  Returns one of two values based on a condition

                                                  Example inputs

                                                  Example outputs

                                                  if(true, true, false)

                                                  true

                                                  if(false, true, false)

                                                  false

                                                  isAfter
                                                  Copy

                                                  Checks if the first date is after the second date

                                                  Example inputs

                                                  Example outputs

                                                  isAfter("2024-05-16", "2024-05-17")

                                                  false

                                                  isAfter("2024-05-17", "2024-05-16")

                                                  true

                                                  isBefore
                                                  Copy

                                                  Checks if the first date is before the second date

                                                  Example inputs

                                                  Example outputs

                                                  isBefore("2024-05-16", "2024-05-17")

                                                  true

                                                  isBefore("2024-05-16", "2024-05-16")

                                                  false

                                                  isBlank
                                                  Copy

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

                                                  Example inputs

                                                  Example outputs

                                                  isBlank("hello")

                                                  false

                                                  isBlank(" ")

                                                  true

                                                  isBlank("")

                                                  true

                                                  isEmpty
                                                  Copy

                                                  Checks if a string is empty

                                                  Example inputs

                                                  Example outputs

                                                  isEmpty("hello")

                                                  false

                                                  isEmpty(" ")

                                                  false

                                                  isEmpty("")

                                                  true

                                                  isValidDate
                                                  Copy

                                                  Checks if a string is a valid date

                                                  Example inputs

                                                  Example outputs

                                                  isValidDate("2024-05-16")

                                                  true

                                                  isValidDate("invalid-date")

                                                  false

                                                  not
                                                  Copy

                                                  Performs logical NOT operation on a boolean value

                                                  Example inputs

                                                  Example outputs

                                                  not(true)

                                                  false

                                                  not(false)

                                                  true

                                                  or
                                                  Copy

                                                  Performs logical OR operation on two boolean values

                                                  Example inputs

                                                  Example outputs

                                                  or(true, false)

                                                  true

                                                  or(false, false)

                                                  false

                                                  propertyExists
                                                  Copy

                                                  Checks if a property exists

                                                  Example inputs

                                                  Example outputs

                                                  propertyExists($.steps.step-1.field)

                                                  true

                                                  smallerThan
                                                  Copy

                                                  Checks if the first number is smaller than the second number

                                                  Example inputs

                                                  Example outputs

                                                  smallerThan(3, 5)

                                                  true

                                                  smallerThan(5, 3)

                                                  false

                                                  smallerThan(3, 3)

                                                  false

                                                  startsWith
                                                  Copy

                                                  Checks if a string starts with another string

                                                  Example inputs

                                                  Example outputs

                                                  startsWith("hello", "he")

                                                  true

                                                  startsWith("world", "he")

                                                  false

                                                  toBoolean
                                                  Copy

                                                  Converts a string to a boolean value

                                                  Example inputs

                                                  Example outputs

                                                  toBoolean("true")

                                                  true

                                                  toBoolean("false")

                                                  false