SpartivoDocs
Open app
Get started
OverviewQuickstartAuthenticationRequests and errors
API reference
RecordsModules and fieldsFilesMessagingDocuments and e-signatureFunctionsWebhooks
Spartivo Script
IntroductionLanguage guideCRM and actionsBuilt-in functionsExamples
Spartivo Script

Built-in functions

Helpers for working with text, lists, maps, dates and numbers. Functions listed as text, list or map methods are called on a value with a dot.

Text

Called on a text value, for example record.name.trim().

text.length()→ number
Number of characters. size() does the same.
text.trim()→ text
Remove spaces from both ends.
text.toUpperCase()→ text
Convert to capital letters.
text.toLowerCase()→ text
Convert to small letters.
text.contains(part)→ true or false
True when the text includes the part. Case matters.
text.containsIgnoreCase(part)→ true or false
Like contains, ignoring capital and small letters.
text.equalsIgnoreCase(other)→ true or false
True when both texts match, ignoring capital and small letters.
text.startsWith(part)→ true or false
True when the text begins with the part.
text.endsWith(part)→ true or false
True when the text ends with the part.
text.matches(pattern)→ true or false
True when the text matches a regular expression.
record.phone.matches("^\\+971")
text.indexOf(part)→ number
Position of the first match, counting from 0, or -1 when it is not found.
text.replace(find, with)→ text
Replace every occurrence. replaceAll() does the same.
text.split(separator)→ list
Cut the text into a list.
"a,b,c".split(",")
text.toList(separator)→ list
Like split, and trims each item. The separator defaults to a comma.
text.substring(start, end)→ text
Part of the text from start up to, not including, end. Counting starts at 0.
text.left(n)→ text
The first n characters.
text.right(n)→ text
The last n characters.
text.padStart(length, fill)→ text
Add the fill character at the start until the text reaches the length.
"7".padStart(3, "0")
text.isEmpty()→ true or false
True when the text has no characters.
text.toNumber()→ number or null
Convert to a number. Thousands commas are ignored. Null when it is not a number.

Lists

Called on a list, for example deals.size(). A list holds up to 5,000 items.

list.add(item)→ the list
Add an item at the end.
list.addAll(other)→ the list
Add every item of another list.
list.size()→ number
Number of items. length() does the same.
list.get(index)→ item or null
The item at a position, counting from 0. list[index] does the same.
list.first()→ item or null
The first item, or null when the list is empty.
list.last()→ item or null
The last item, or null when the list is empty.
list.contains(item)→ true or false
True when the list has the item.
list.indexOf(item)→ number
Position of the item, or -1.
list.remove(index)→ item or null
Remove the item at a position and return it.
list.removeElement(item)→ the list
Remove the first matching item.
list.isEmpty()→ true or false
True when the list has no items.
list.join(separator)→ text
Combine the items into one text.
names.join(", ")
list.sort(order)→ list
A sorted copy, smallest first. Pass "desc" for largest first.
list.reverse()→ list
A copy in the opposite order.
list.sum()→ number
Add up the numbers in the list.
list.distinct()→ list
A copy without repeated items.
list.subList(start, end)→ list
Part of the list from start up to, not including, end.
list.pluck(key)→ list
From a list of maps, collect one key from each.
amounts = deals.pluck("amount");
list.clear()→ the list
Remove every item.

Maps

Called on a map, for example settings.get("region"). map.key and map["key"] also read a value.

map.get(key)→ value or null
The value for a key, or null.
map.put(key, value)→ the map
Set a value.
map.putAll(other)→ the map
Copy every key from another map.
map.containsKey(key)→ true or false
True when the key exists.
map.keys()→ list
All keys.
map.values()→ list
All values.
map.remove(key)→ value or null
Delete a key and return its value.
map.size()→ number
Number of keys.
map.isEmpty()→ true or false
True when the map has no keys.
map.toString()→ text
The map as JSON text.

Dates and times

Dates are text in ISO form: "2026-11-18" for a date, "2026-11-18T09:30:00.000Z" for a date and time (UTC).

now()→ date-time text
The current date and time.
today()→ date text
Today's date.
addDays(date, n)→ date
Move a date forward by n days. Use a negative number to go back.
due = addDays(today(), 7);
addHours(date, n)→ date-time text
Move forward by n hours.
addMinutes(date, n)→ date-time text
Move forward by n minutes.
addMonths(date, n)→ date
Move forward by n months.
daysBetween(from, to)→ number
Whole days from the first date to the second.
age = daysBetween(record.createdAt, now());
hoursBetween(from, to)→ number
Hours from the first date to the second, to two decimals.
formatDate(date, pattern)→ text
Write a date as text. Pattern letters: yyyy, MM, MMM, dd, HH, mm, ss.
formatDate(record.close_date, "dd MMM yyyy")
toDate(value)→ date text
Keep only the date part.
toDateTime(value)→ date-time text
Convert to a full date and time.
year(date)→ number
The year as a number.
month(date)→ number
The month, 1 to 12.
day(date)→ number
The day of the month.
weekday(date)→ text
The day name, for example "Monday".

Numbers

Maths helpers. round, floor, ceil, abs, toFixed and format can also be called on a number, for example total.round(2).

round(x, decimals)→ number
Round to a number of decimals. Decimals defaults to 0.
round(total * 0.05, 2)
floor(x)→ number
Round down.
ceil(x)→ number
Round up.
abs(x)→ number
Remove the minus sign.
min(a, b, …)→ number
The smallest value. Also accepts one list.
max(a, b, …)→ number
The largest value. Also accepts one list.
random(n)→ number
A random whole number from 0 up to n - 1. Without n, a decimal between 0 and 1.
toNumber(x)→ number or null
Convert text to a number. Null when it is not a number.

General

Checks, conversion and encoding.

ifNull(value, fallback)→ value
The fallback when the value is null or empty text; otherwise the value.
amount = ifNull(record.amount, 0);
isNull(value)→ true or false
True when the value is null.
isEmpty(value)→ true or false
True for null, empty text, an empty list or an empty map.
len(value)→ number
Length of text or a list, or the number of keys in a map.
toString(value)→ text
Convert anything to text. toText() does the same.
toList(value)→ list
Wrap a single value in a list. A list is returned as it is.
toJson(value)→ text
Write a map or list as JSON text.
parseJson(text)→ map or list
Read JSON text into a map or list. Stops the function when the text is not valid JSON, so wrap it in try when unsure.
uuid()→ text
A new random identifier.
encodeUrl(text)→ text
Make text safe to place in a web address.
decodeUrl(text)→ text
Reverse of encodeUrl.
Map()→ map
A new empty map. {} does the same.
List()→ list
A new empty list. [] does the same.
Previous← CRM and actionsNextExamples →
On this page
TextListsMapsDates and timesNumbersGeneral