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()→ numberNumber of characters. size() does the same.
text.trim()→ textRemove spaces from both ends.
text.toUpperCase()→ textConvert to capital letters.
text.toLowerCase()→ textConvert to small letters.
text.contains(part)→ true or falseTrue when the text includes the part. Case matters.
text.containsIgnoreCase(part)→ true or falseLike contains, ignoring capital and small letters.
text.equalsIgnoreCase(other)→ true or falseTrue when both texts match, ignoring capital and small letters.
text.startsWith(part)→ true or falseTrue when the text begins with the part.
text.endsWith(part)→ true or falseTrue when the text ends with the part.
text.matches(pattern)→ true or falseTrue when the text matches a regular expression.
record.phone.matches("^\\+971")text.indexOf(part)→ numberPosition of the first match, counting from 0, or -1 when it is not found.
text.replace(find, with)→ textReplace every occurrence. replaceAll() does the same.
text.split(separator)→ listCut the text into a list.
"a,b,c".split(",")text.toList(separator)→ listLike split, and trims each item. The separator defaults to a comma.
text.substring(start, end)→ textPart of the text from start up to, not including, end. Counting starts at 0.
text.left(n)→ textThe first n characters.
text.right(n)→ textThe last n characters.
text.padStart(length, fill)→ textAdd the fill character at the start until the text reaches the length.
"7".padStart(3, "0")text.isEmpty()→ true or falseTrue when the text has no characters.
text.toNumber()→ number or nullConvert 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 listAdd an item at the end.
list.addAll(other)→ the listAdd every item of another list.
list.size()→ numberNumber of items. length() does the same.
list.get(index)→ item or nullThe item at a position, counting from 0. list[index] does the same.
list.first()→ item or nullThe first item, or null when the list is empty.
list.last()→ item or nullThe last item, or null when the list is empty.
list.contains(item)→ true or falseTrue when the list has the item.
list.indexOf(item)→ numberPosition of the item, or -1.
list.remove(index)→ item or nullRemove the item at a position and return it.
list.removeElement(item)→ the listRemove the first matching item.
list.isEmpty()→ true or falseTrue when the list has no items.
list.join(separator)→ textCombine the items into one text.
names.join(", ")list.sort(order)→ listA sorted copy, smallest first. Pass "desc" for largest first.
list.reverse()→ listA copy in the opposite order.
list.sum()→ numberAdd up the numbers in the list.
list.distinct()→ listA copy without repeated items.
list.subList(start, end)→ listPart of the list from start up to, not including, end.
list.pluck(key)→ listFrom a list of maps, collect one key from each.
amounts = deals.pluck("amount");list.clear()→ the listRemove 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 nullThe value for a key, or null.
map.put(key, value)→ the mapSet a value.
map.putAll(other)→ the mapCopy every key from another map.
map.containsKey(key)→ true or falseTrue when the key exists.
map.keys()→ listAll keys.
map.values()→ listAll values.
map.remove(key)→ value or nullDelete a key and return its value.
map.size()→ numberNumber of keys.
map.isEmpty()→ true or falseTrue when the map has no keys.
map.toString()→ textThe 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 textThe current date and time.
today()→ date textToday's date.
addDays(date, n)→ dateMove a date forward by n days. Use a negative number to go back.
due = addDays(today(), 7);addHours(date, n)→ date-time textMove forward by n hours.
addMinutes(date, n)→ date-time textMove forward by n minutes.
addMonths(date, n)→ dateMove forward by n months.
daysBetween(from, to)→ numberWhole days from the first date to the second.
age = daysBetween(record.createdAt, now());hoursBetween(from, to)→ numberHours from the first date to the second, to two decimals.
formatDate(date, pattern)→ textWrite a date as text. Pattern letters: yyyy, MM, MMM, dd, HH, mm, ss.
formatDate(record.close_date, "dd MMM yyyy")toDate(value)→ date textKeep only the date part.
toDateTime(value)→ date-time textConvert to a full date and time.
year(date)→ numberThe year as a number.
month(date)→ numberThe month, 1 to 12.
day(date)→ numberThe day of the month.
weekday(date)→ textThe 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)→ numberRound to a number of decimals. Decimals defaults to 0.
round(total * 0.05, 2)floor(x)→ numberRound down.
ceil(x)→ numberRound up.
abs(x)→ numberRemove the minus sign.
min(a, b, …)→ numberThe smallest value. Also accepts one list.
max(a, b, …)→ numberThe largest value. Also accepts one list.
random(n)→ numberA random whole number from 0 up to n - 1. Without n, a decimal between 0 and 1.
toNumber(x)→ number or nullConvert text to a number. Null when it is not a number.
General
Checks, conversion and encoding.
ifNull(value, fallback)→ valueThe fallback when the value is null or empty text; otherwise the value.
amount = ifNull(record.amount, 0);isNull(value)→ true or falseTrue when the value is null.
isEmpty(value)→ true or falseTrue for null, empty text, an empty list or an empty map.
len(value)→ numberLength of text or a list, or the number of keys in a map.
toString(value)→ textConvert anything to text. toText() does the same.
toList(value)→ listWrap a single value in a list. A list is returned as it is.
toJson(value)→ textWrite a map or list as JSON text.
parseJson(text)→ map or listRead 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()→ textA new random identifier.
encodeUrl(text)→ textMake text safe to place in a web address.
decodeUrl(text)→ textReverse of encodeUrl.
Map()→ mapA new empty map. {} does the same.
List()→ listA new empty list. [] does the same.