Novulo Expression String functions.
This plugin exposes functions on the string typehandler, as well as provide the option to the architect user to map the function implementation to a user defined typehandler, that evaluate an expression string and returns a value of type, depending on which function has been used.
Currently the functions can be used to evaluate expression strings that evaluate to the following types
- string
- int
- float
- boolean
The user-mapped functions, can evaluate to whatever type is configured via configuration
Important
It is important to be careful how these functions are used. Since it is an expression string, evaluated not in the way it is meant to be evaluated, it can become quite performance heavy if for example, these functions are used on grids (for example as filter expression or as a Function Column). If they are used as a column, it means that the expression is evaluated for each row on the grid. For complex expressions and grids with many rows, this could result in quite a heavy performance impact. This is why developers should be careful with how these functions are used and what expressions are evaluated with them.
Available functions
All 4 functions have the same format and usage, they differ only in the return data type
All of them are called on a string
All of them have the same parameters
- List “contexts” - the contexts to set to the expression.
- For example [ persons:load(1), organizations:load(23), configurations:load(10) ]
- when the expression to evaluate contains “this” - it will be replaced with “persons:load(1)”
- when the expression to evaluate contains “parent” - it will be replaced with “organizations:load(23)”
- when the expression to evaluate contains “parent.parent” - it will be replaced with “configurations:load(10)”
- etc..
- For example [ persons:load(1), organizations:load(23), configurations:load(10) ]
For example:
- “this.full_name()”.evaluatetoexpressionstring( [ persons:load(1), organizations:load(23), configurations:load(10) ])
- there is a persons record with id 1 and full name “John Doe”
- The result from “this.full_name()”.evaluatetoexpressionstring( [ persons:load(1), organizations:load(23), configurations:load(10) ]) will be “John Doe”
EvaluateExpressionToString
- Return type is String
EvaluateExpressionToToInt
- Return type is Int
EvaluateExpressionToFloat
- Return type is Float
EvaluateExpressionToBoolean
- Return type is Boolean
Example usages
These functions can be used in the expression debugger, as well as other cases where Novulo expressions are used.
Again, be careful how these functions are used, in what context and what expressions are actually evaluated, as they can result in being quite heavy to evaluate
These functions can also be used in Plugin configurations. For example, on my configuration record, i have this field
-
CSS color - a validated expression field (String Extensions plugin structure item)
-
Here is how it looks with the expression filled in
-
The configuration in the architect looks like this:
-
This expression field, i use in another plugin item - ExtendedGrid panel, which supports colouring rows based on the configured value. This supports expressions
Here is the expression expanded:
Here i check if there is actually expression set to evaluate - if no, then just don’t set a colour, if there is - using the EvaluateExpressionStringToString, i retrieve the value to set to this configuration item.
The above configuration, when the ExtendedGrid is rendered and the configuraiton evaluated results in :
If we look at the configured expression again:
-
string:if(this.id.modulo(2).equals(0),“#17b01c***”,“#1c17b0”)***
We see that: -
rows that have an EVEN id - are coloured in green (#17b01c)
-
rows that have an ODD id - are coloured in blue (#1c17b0***)***