You are reading the documentation for an outdated Corteza release. 2024.9 is the latest stable Corteza release.

Field expression functions

Text functions

Function Signature Description Example

trim

trim(string)

The function removes the leading and trailing whitespaces, see strings.TrimSpace

trim(" foo ") results in "foo"

trimLeft

trimLeft(string, chars)

The function removes the leading occurence of characters

trimLeft("!!foo", "!1") results in "foo"

trimRight

trimRight(string, chars)

The function removes the trailing occurence of characters

trimRight("foo!!", "!1") results in "foo"

length

length(string)

The function returns the length of the string

length("") returns 0

toLower

toLower(string)

The function converts all characters to lowercase.

toLower("FOO") results in "foo"

toUpper

toUpper(string)

The function converts all characters to uppercase.

toUpper("fOo") results in "FOO"

shortest

shortest(arg1, arg2, …​argN)

The function returns the shortest string.

shortest("foo", "foobar") results in "foo"

longest

longest(arg1, arg2, …​argN)

The function returns the longest string.

longest("foo", "foobar") results in "foobar"

format

format(format, arg1, arg2, …​argN)

Returns the formatted string., see String formatting for available formatting options.

format("test %d", 10) results in "test 10"

title

title(string)

The function returns the first character uppercased in line of strings.

title("this SHOULD be titled") results in "This SHOULD be titled"

untitle

untitle(string)

The function returns the first character lowercased in line of strings.

untitle("This SHOULDnt Be Titled") results in "this SHOULDnt Be Titled"

repeat

repeat(string, count)

The function repeats string n times, see strings.Repeat

repeat("! ", 3) results in "! ! ! "

replace

replace(string, old, new, count)

The function returns a copy of the string s with the first n non-overlapping instances of old replaced by new, see strings.Replace

replace(" foo foo foo", "foo", "bar", 1) results in " bar foo foo"

split

split(string, separator)

The function slices s into all substrings separated by sep and returns a slice of the substrings between those separators, see strings.Split

split("foo-bar", "-") results in [foo bar]

join

join(strings, separator)

The function concatenates the elements of its first argument to create a single string, see strings.Join

join(["foo", "bar"], "-") results in "foo-bar"

substring

substring(string, start, end)

The function extracts a substring from original string specifying end value will not match till end of string

substring("foobar", 1, -1) results in "oobar"

shorten

shorten(string, type, count)

The function shortens by type (char / word) to {count} occurences followed by ellipsis

shorten("This is a whole sentence", "word", 4) results in "This is a whole …"

camelize

camelize(string)

The function camelizes string

camelize("Foo bar") results in "fooBar"

snakify

snakify(string)

The function snakifies string

snakify("Foo bar baz") results in "foo_bar_baz"

isUrl

isUrl(string)

The function returns true if url is valid

isUrl("//not-valid") results in false

isEmail

isEmail(string)

The function returns true if an email is valid

isEmail("@cortezaproject.) results in false

hasSubstring

`hasSubstring(string, substring, case)

The function checks if a substring exists in original string use watchCase if need case sensitivity

hasSubstring(" foobar ", "Bar", true) results in false

hasPrefix

hasPrefix(string)

The function tests whether the string s begins with prefix, see strings.HasPrefix

hasPrefix(" foobar", " foo") results in true

hasSuffix

hasSuffix(string)

The function tests whether the string s ends with suffix, see strings.hasSuffix

hasSuffix(" foobar", " ar") results in false

Numeric functions

Function Signature Description Example

min

min(arg1, arg2, …​argN)

The function returns item with the lowest value.

min(0, 1, 2) results in 0

max

max(arg1, arg2, …​argN)

The function returns item with the highest value.

max(0, 1, 2) results in 2

round

round(number, digits)

The function rounds a floating point number to the specified number of digits.

round(3.14, 1) results in 3.1

floor

floor(number)

The function rounds number down to the nearest integer.

floor(3.14) results in 3

ceil

ceil(number)

The function rounds number up to the nearest integer.

ceil(3.14) results in 4

abs

abs(number)

The function returns the absolute value of x, see math.Abs

avs(-13) results in 13.0

log

log(number)

The function returns the decimal logarithm of x, see math.Log10

log(100) results in 10.0

pow

pow(number, number)

The function returns x**y, the base-x exponential of y, see math.Pow

pow(2, 3) results in 8

sqrt

sqrt(number)

The function returns correctly rounded sqrt, see math.Sqrt

sqrt(4) results in 2

sum

sum(…​argN)

The function returns the sum of all arguments

sum(1, 2, 3) results in 6

average

sum(…​argN)

The function returns the average of all arguments

average(1, 2) returns 1.5

List functions

Function Signature Description Example

push

push(arg1, …​argN)

The function adds an element to the end of list and returns the list.

push(strings, str1, str2) results in [str0, str1, str2]

pop

pop(arg)

The function returns the last element off the list.

pop([1,2,3]) results in 3

shift

shift(arg)

The function returns the first element of the list.

shift([1,2,3]) results in 1

count

count(arg)

The function returns the number of items when provided as an argument, or the entire length of the array when no argument is provided.

count([]) results in 0; count("foo", "o") results in 2

has

has(arg, …​argN)

The function returns true if any of the values exist in first element

has([1,2], 2) results in true

hasAll

hasAll(arg, …​argN)

The function returns true if all of the values exist in first element

hasAll([1,2], 2) results in false

sort

sort(arg, boolean)

The function sorts list elements ascending or descending as per second argument and returns the list.

sort([5,1,3,2], false) results in [1,2,3,5]; sort([5,1,3,2], true) results in [5,3,2,1]

KV functions

The resulting type of the KV function is based on the first argument. You may not provide multiple different KV types (KV, KVV, Vars) into the same function.

To examplify; merge(KV, KVV, Vars) is not allowed.

Function Signature Description Example

set

set(KV, key, value)

The function assigns a value to the given KV type.

set(&KV{"foo": "foo"}, "foo", "bar") results in &KV{"foo": "foo"}, Same for KVV and Vars.

merge

merge(KV, arg1, …​argN)

The function combines all of the given KV types into a single KV type.

merge(&KVV{"foo": ["foo"]}, &KVV{"bar": ["bar"]}) results in &KVV{"foo": ["foo"], "bar": ["bar"]}, Same for KV and Vars.

filter

filter(KV, arg1, …​argN)

The function returns a KV type with only the specified key-value pairs.

filter(&KVV{"foo": ["foo"], "bar": ["bar"]}, "foo", "example") results in &KVV{"foo": ["foo"]}, Same for KV and Vars.

omit

omit(KV, arg1, …​argN)

The function returns a KV type without the specified key-value pairs.

filter(&KV{"foo": "foo", "bar": "bar"}, "foo", "example") results in &KVV{"bar": "bar"}, Same for KV and Vars.

General functions

Function Signature Description Example

coalesce

coalesce(arg1, arg2, …​argN)

The function returns the first non null value

coalesce(null, 0, 1, 2) results in 0

isEmpty

isEmpty(arg)

The function returns true if the value is empty

isEmpty("") results in true

isNil

isNil(arg)

The function returns true if the value is Nil

isNil(emptyVar) results in true

Date Time functions

Function Signature Description Example

earliest

earliest(arg1, arg2, …​argN)

The function returns earliest DateTime.

earliest(datefield1, datefield2) results in "1970-01-01T00:00:00"

latest

latest(arg1, arg2, …​argN)

The function returns latest DateTime.

latest(datefield1, datefield2) results in "1970-01-01T00:30:00"

parseISOTime

parseISOTime(datetime)

The function returns parsed ISO DateTime.

parseISOTime(datefield) results in "1970-01-01T00:00:00+00:00"

modTime

modTime(datetime, duration)

The function returns the modified time part of the DateTime.

modTime(datefield, "+30m") results in "1970-01-01T00:30:00"

modDate

modDate(datetime, duration)

The function returns modified day part of the DateTime.

modDate(datefield, "1") results in "1970-01-02T00:00:00"

modWeek

modWeek(datetime, duration)

The function returns modified week part of the DateTime.

modWeek(datefield, "1") results in "1970-01-08T00:00:00"

modMonth

modMonth(datetime, duration)

The function returns modified month part of the DateTime.

modMonth(datefield, "1") results in "1970-02-01T00:00:00"

modYear

modYear(datetime, duration)

The function returns modified year part of the DateTime.

modYear(datefield, "1") results in "1971-01-01T00:00:00"

parseDuration

parseDuration(duration)

The function returns parsed duration.

parseDuration("2h") results in "2h0m0s"

strftime

strftime(datetime, format)

The function returns DateTime string for the specified date and format, see Date and time formatting for available formatting options.

strftime(datefield, "%Y-%m-%d") results in "1970-01-01"

now

now(datetime)

The function returns current DateTime string.

now() results in "1970-01-01T00:00:00+00:00"

isLeapYear

isLeapYear(datetime)

The function returns true if the specified year is leap year.

isLeapYear(datefield) results in true

isWeekDay

isWeekDay(datetime)

The function returns true if the specified day is week day.

isWeekDay(datefield) results in true

String formatting

%v

Description

Returns the raw value.

Example

format("%v", "test") results in "test"

%t

Description

Returns the boolean value as true/false.

Example

format("%t", true) results in "true"

%b

Description

Returns the number in base 2 (in the binary format).

Example

format("%b", 10) results in "1010"

%d

Description

Returns the number in base 10.

Example

format("%d", 10) results in "10"

%o

Description

Returns the number in base 8.

Example

format("%o", 10) results in "12"

%O

Description

Returns the number in base 8 with 0o prefix.

Example

format("%O", 10) results in "0o12"

%x

Description

Returns the number in base 16; lower-case a-f.

Example

format("%x", 10) results in "a"

%X

Description

Returns the number in base 16; upper-case A-F.

Example

format("%X", 10) results in "A"

%b

Description

Returns the floating point number in scientific notation with binary exponent.

Example

format("%b", 10.11) results in "5691424029089464p-49"

%e

Description

Returns the floating point number in scientific notation; lower-case e.

Example

format("%e", 10.11) results in "1.011000e+01"

%E

Description

Returns the floating point number in scientific notation; upper-case E.

Example

format("%E", 10.11) results in "1.011000E+01"

%f

Description

Returns the floating point number with a decimal point.

Example

format("%f", 10.11) results in "10.110000"

Date and time formatting

%Y

Description

Returns the year with century as a decimal number.

example

strftime(dateField, "%Y") results in "1993"

%y

Description

Returns the year without century as a decimal number (00-99).

example

strftime(dateField, "%y") results in "93"

%C

Description

Returns year / 100 as a decimal number; single digits are preceded by a zero.

example

strftime(dateField, "%C") results in "19"

%m

Description

Returns the month as a decimal number (01-12).

example

strftime(dateField, "%m") results in "02"

%B

Description

Returns the full national month name.

example

strftime(dateField, "%B") results in "February"

%b

Description

Returns the abbreviated national month name.

example

strftime(dateField, "%b") results in "Feb"

%U

Description

Returns the week number of the year (Sunday as the first day of the week) as a decimal number (00-53).

example

strftime(dateField, "%U") results in "05"

%V

Description

Returns the week number of the year (Monday as the first day of the week) as a decimal number (01-53).

example

strftime(dateField, "%V") results in "05"

%W

Description

Returns the week number of the year (Monday as the first day of the week) as a decimal number (00-53).

example

strftime(dateField, "%W") results in "05"

%A

Description

Returns the full national weekday name.

example

strftime(dateField, "%A") results in "Tuesday"

%a

Description

Returns the abbreviated national weekday name.

example

strftime(dateField, "%a") results in "Tue"

%d

Description

Returns the day of the month as a decimal number (01-31).

example

strftime(dateField, "%d") results in "02"

%e

Description

Returns the day of the month as a decimal number (1-31).

example

strftime(dateField, "%e") results in " 2"

%j

Description

Returns the day of the year as a decimal number (001-366).

example

strftime(dateField, "%j") results in "033"

%u

Description

Returns the weekday (Monday as the first day of the week) as a decimal number (1-7).

example

strftime(dateField, "%u") results in "5"

%w

Description

Returns the weekday (Sunday as the first day of the week) as a decimal number (0-6).

example

strftime(dateField, "%w") results in "2"

%H

Description

Returns the hour (24-hour clock) as a decimal number (00-23).

example

strftime(dateField, "%H") results in "06"

%k

Description

Returns the hour (24-hour clock) as a decimal number (0-23).

example

strftime(dateField, "%k") results in " 6"

%I

Description

Returns the hour (12-hour clock) as a decimal number (01-12).

example

strftime(dateField, "%I") results in "06"

%l

Description

Returns the hour (12-hour clock) as a decimal number (1-12).

example

strftime(dateField, "%l") results in " 6"

%M

Description

Returns the minute as a decimal number (00-59).

example

strftime(dateField, "%M") results in "00"

%S

Description

Returns the second as a decimal number (00-60).

example

strftime(dateField, "%S") results in "00"

%S

Description

Returns the millisecond as a decimal number (000-999).

example

strftime(dateField, "%S") results in "000"

%p

Description

Returns the national representation of either "ante meridiem" (a.m.) or "post meridiem" (p.m.).

example

strftime(dateField, "%p") results in "AM"

%c

Description

Returns the national representation of time and date.

example

strftime(dateField, "%c") results in "Tue Feb 2 06:00:00 1993"

%X

Description

Returns the national representation of the time.

example

strftime(dateField, "%X") results in "06:00:00"

%x

Description

Returns the national representation of the date.

example

strftime(dateField, "%x") results in "02/02/93"

%Z

Description

Returns the time zone name.

example

strftime(dateField, "%Z") results in "-0500"

%z

Description

Returns the time zone offset from UTC.

example

strftime(dateField, "%z") results in "-0500"

%n

Description

Returns a newline (\n).

example

strftime(dateField, "%n") results in "\n"

%t

Description

Returns a tab.

example

strftime(dateField, "%t") results in "\t"

%%

Description

Returns a %.

example

strftime(dateField, "%%") results in "%"

%F

Description

Equivalent to %Y-%m-%d.

example

strftime(dateField, "%F") results in "1993-02-02"

%D

Description

Equivalent to %m/%d/%y.

example

strftime(dateField, "%D") results in "02/02/93"

%R

Description

Equivalent to %H:%M.

example

strftime(dateField, "%R") results in "06:00"

%r

Description

Equivalent to %I:%M:%S %p.

example

strftime(dateField, "%r") results in "06:00:00 AM"

%T

Description

Equivalent to %H:%M:%S.

example

strftime(dateField, "%T") results in "06:00:00"

%v

Description

Equivalent to %e-%b-%Y.

example

strftime(dateField, "%v") results in " 2-Feb-1993"