Expressions: Frequently Used Functions

Expressions: Frequently Used Functions

Below is a list of frequently used functions that you can use per data type. Since every application can have a different composition, some functions may not be available in your application (yet).

To find a complete list of all functions in your application, check the data model in the Expression Debugger.

For a fundamental explanation of our expression language and its syntax, you can take a look at Expressions in Novulo.

  • Some functions can be applied without context, which takes the form DataType:function(). These are called static functions;
  • Other functions can only be applied to a context object, which is always denoted as ContextObject.function(). These are called non-static functions. A context object is any result of an expression; a record, a string, an integer, etc.

String functions

Static

Function Returns Explanation
string: join(stringX, list) string Pastes all values of the list behind eachother, separated by stringX
Examples; try in the expression debugger!
Function Example
string:join(stringX, list) string:join(" - ",["Hello","world","with","dashes!"]), string:join("".appendnewline(),{persons,first_name,age.isgreater(100)})

Non-static

Function Returns Explanation
stringX. appendnewline()[1] string Adds a line break
stringX. concat(stringY) string Pastes stringY behind stringX
stringX. contains(stringY) boolean Checks if stringY appears in stringX[2]
stringX. endswith(stringY) boolean Checks if stringY appears at the end of stringX[2:1]
stringX. isinteger()[1:1] boolean Checks if stringX can be transformed to an integer
stringX. isnullorempty()[1:2] boolean Checks if a string is empty or equal to ""
stringX. length()[1:3] int Counts the characters in a string
stringX. replace(stringY, stringZ)[1:4] string Replaces all instances of stringY of stringX with stringZ
stringX. startswith(stringY) boolean Checks if stringY appears at the beginning of stringX
stringX. substring(intX, intY)[1:5] string Returns a subset of characters from stringX with length intY, starting at the intX position
stringX. tointeger()[1:6] int Transforms stringX into an integer
stringX. tolower()[1:7] string Replaces all capital letters in stringX with lowercase letters
stringX. toupper()[1:8] string Replaces all lowercase letters in stringX with capital letters
Examples; try in the expression debugger!
Function Example
appendnewline() "Hello".appendnewline().appendnewline().concat("world!")
concat(string) "Hello".concat(" world!")
contains(string) "Hello world!".contains("hello")
endswith(stringY) "Hello world!".endswith("world!")
equals(stringY) "Hello world!".equals("hello world!")
isinteger() "123".isinteger()
isnullorempty() "".isnullorempty(), see the difference with "".isnull()!
length() "Hello world!".length()
replace(stringY, stringZ) "Hello Novulo!".replace("Novulo!","world!")
startswith(stringY) "Hello world!".startswith("hello")
substring(intX, intY) "I prefer my examples to say Hello world!".substring(28,12)
tointeger() "123".tointeger()
tolower() "HELLO WORLD!".tolower()
toupper() "hello world!".toupper()

Boolean functions

These are especially useful in filters (in lists, export definitions) and transitions of processes and workflows.

Static

Function Returns Explanation
boolean: not(booleanX) boolean Returns true if booleanX is false, and vice versa
boolean: and(list) boolean The list must be a list of boolean expressions. If every expression returns true, the and(list) expression returns true as well. If even one expression returns false, the and(list) expression returns false too!
boolean: or(list) boolean The list must be a list of boolean expressions. If even one expression returns true, the or(list) expression returns true as well. If every expression returns false, the or(list) expression returns false too!
Examples; try in the expression debugger!
Function Example
boolean:not(booleanX) boolean:not(int:load(1).add(1).equals(3))
boolean:and(list) boolean:and(["Hello".equals("hello"), "World!".equals("world!")])
boolean:or(list) boolean:or(["Hello".equals("goodbye"), "World!".equals("world!")])

“Generic” functions

“Generic” of course isn’t a data type. However, some functions can be evaluated in all data types. These are summarized here.

Static

Function Returns Explanation
DataType: if(booleanX, then, else) DataType Evaluates booleanX: if true, returns the expression in then, if false, returns the expression in else. The else and then expressions must result in the declared DataType
DataType: case(switch, tuplelist, default) DataType Evaluates switch, then looks up the first matching key in the tuplelist, and returns the accompanied value. If no match is found, default is returned. The values of the tuples must result in the declared DataType. The keys of the tuples must result in the same data type as the switch
Examples; try in the expression debugger!
Function Example
DataType:if(booleanX, then, else) string:if(boolean:and([date:now().getdayofmonth().equals(1),date:now().getmonth().equals(1)]),"Happy new year!","")
DataType:case(switch, tuplelist, default) string:case(date:now().getmonth().tostring().concat("-") .concat(date:now().getdayofmonth().tostring()), [<"1-1","Happy New Year!">, <"2-14","Happy Valentine's Day!">, <"3-14","Happy Pi Day!">, <"4-1","Happy April Fools' Day!">], "")

Non-static

Function Returns Explanation
ContextObject. equals(value) boolean Checks if value is the same as the context object. The value must have the same data type as the context object
ContextObject. isnull() boolean Checks if the context object is empty
Examples; try in the expression debugger!
Function Example
equals(value) "Hello".concat(" world!").equals("hello world!"), note that string:getnull().equals(string:getnull()) returns false! Always use .isnull() in stead of .equals(DataType:getnull())
isnull() string:getnull().isnull(), "".isnull()

“List” functions

Similarly to the generic functions, these functions are not technically “list” functions. They are all evaluated in some data type and return another data type, but these all have a list as a parameter.

Remember that a list expression comes in the form {DataType, Expression, Filter, Sorting}, or as [Expression1, Expression2, ...etc.] as described here.

The result of the Expression of the list must be the same as the declared data type.
So these are valid:

  • persons:count({persons, this})
  • int:count({persons, age()})
  • string:count({persons, first_name})

While int:count({persons, this}) is not!

Static

Function Returns Explanation
DataType: count(list) int Counts the values in the list
DataType: exists(list) boolean Checks if the list has at least one value
DataType: first(list) DataType Returns the first value in the list
DataType: itemat(list, intX) DataType Returns the intX-th value in the list
DataType:[3] min(list) DataType Returns the lowest value in the list
DataType:[3:1] max(list) DataType Returns the highest value in the list
DataType:[3:2] sum(list) DataType Sums the values in the list
Examples; try in the expression debugger!
Function Example
count(list) persons:count({persons, this}), int:count({persons, age()}), string:count({persons, first_name})
exists(list) persons:exists({persons,this,age().isgreater(100)})
first(list) persons:first({persons, this, age().isnotnull(), birthday.addyears(age()).getdaysto(date:now()).desc})

Non-static

Function Returns Explanation
DataType: in([list]) boolean Checks if the value appears in the list
Examples; try in the expression debugger!
Function Example
in([string]) "world".in(["Hello Novulo!", "Hello world!"])

  1. Requires the String Extensions plugin ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎

  2. Is much slower than startswith(stringY) or equals(stringY)! Do not use these in filters. ↩︎ ↩︎

  3. Only int, float, money, percentage ↩︎ ↩︎ ↩︎

5 Likes