-
-
-
- Building blocks of the data model
- Basic concepts
- Classes
- Key fields
- Local lookup lists
- Fields and data types
- Defining the columns of a table
- Relations between classes
- Global lookup lists
- Filters
- Universal connected classes
- Deleting foreign records
- Class inheritance
- Storage of personal data on test and develop environment (scrambling)
-
- User interface versions
- Building blocks for user interface design
- Adding styles with a css
- Surrounding page
- Changing snippets
- Creating a custom login page (pre 3.4)
- Creating a custom login page
- Using velocity templates within the blueprint
- Create your own web pages
- HTML delivery requirements
- How to customize system mails
-
- Resource files
- Velocity - How does it work?
- Quick Velocity Tutorial
- Debugging velocity scripts
- Velocity Command Reference
- Script Editor Tutorial
- Using velocity for calculations
- Using predefined forms in a html design
- Velocity forms
- Data field identifiers
- Macros and methods
- Velocity library
- Velocity: using the #macro command
- velocity and xml
- Using AJAX in your velocity scripts
-
-
- Argon2 password conversion
- Introduction to security
- Secure development
- Security certification
- Security Exam
- Field properties concerning security
- Developing user groups securely
- Security considerations for user interface
- Secure file organization
- Securely using the request
- Cross Site Scripting (XSS)
- Other options concerning secure development
- Security analysis
- Secure deployment
- Secure application management
- Scrambling of testdata
- Anonymization of personal data
- Using robots.txt
- Permission settings
- Security measures
- Data encryption
-
- Search Engine Optimization
- OTP
- User Interface migration guide
- User account management
- Instructies voor implementatie van visueel editen van nieuwsbrieven
- Login as another user
- Support
- More information about moving to User Interface Version 4.0
- Standaard page layout
- Sections moved to layout
- Aanpassingen in release 2024-7
- Media library
- Aanpassingen in release 2024-10
- Analytics and Matomo
- Registration forms
- How to change names of classes and fields?
- Responsible Disclosure Policy
- How to upload a blob in Velocity?
- Aanpassingen in release 2024-2
- Instances
- Componenten in onze technologie
- Google Analytics
- Street and City helper (postcodecheck)
- Responsible disclosure-beleid
- Postcode check service (straat en huisnummer) kosten
- Expressions
- Regular Expression Reference
-
Using velocity for calculations
In the CrossmarX Application Engine velocity can also be used to perform calculations. Velocity calculations are often used in cases where data is required from related classes or when CrossmarX Expressions become too verbose.
Context variables
In velocity calculations, the context already contains some variables.
| Variable | Type | Java object |
Description |
| record | input | Record |
The record containing all fields of an object. |
| session | input | Session |
Session is the object where all information about a single user session is stored. Every web user has its own Session object |
| return | output | The variable for setting the value of the calculated field. You have to assign the result of the calculation to this variable. It is read by the component managing calculated fields, which sets the field value to the value read from the variable |
Some simple examples
In this example the calculated field of the record gets the same value as the value read from another field of the record:
#set($return = $record.get("other field name"))
The right hand side in the example above is a straight forward value. It can also be an expression with arithmetic or string operators to calculate a value:
#set($return = "field value is " + $record.get("other field name"))
or:
#set($return = 2 * 3)
You can use conditional expressions to get the return value. The ''other field name" should be of datatype decimal or whole number:
#if ($record.get("other field name") > 1)
#set($return = "many")
#else
#set($return = "one or less")
#end
You can use loops to add values. Set $return to 0 so the calculation can be made and "field name" should have a numeric datatype
#set($return = 0)
#foreach($rec in $table)
#set($return = $return + $rec.get("field name"))
#end
Getting a foreign record
An example which uses not only the record itself but a related record. This is where velocity gets really useful.
#set($foreignrecord = $record.getForeignRecord("foreign class name"))
#if($foreignrecord)
#set($return = $foreignrecord.get("foreign record field name"))
#end
Getting a connected table
An example which uses not only the record itself but a connected table."a field" should have a numeric datatype
#set($return = 0)
#set($connectedTable = $record.getConnectedTable("connected table name"))
#foreach($otherRecord in $connectedTable)
#set($return = $return + $otherRecord.get("a field"))
#end
An example which uses not only the record itself but a connected table."a field" should have a numeric datatype
This is the same as the previous example but now "a field" is of datatype Money. The use the field in a calculation it has to be converted to cents
#set($return = 0)
#set($connectedTable = $record.getConnectedTable("connected table name"))
#foreach($otherRecord in $connectedTable)
#set($return = $return + $otherRecord.get("a field").getCents())
#end
Other features - setting the value of another field
A calculated field is a 'read-only' field, since its value is set by the calculation. Besides setting the value of its own field, a calculated field can set the value of another field. Call getEditableRecord() and then set the value
#set($return = some value)
#set($record = $record.getEditableRecord())
$record.put("first name", $return)
Because a calculated field can set the value of other fields, you can use it as a 'field value manager'. The calculated field itself can be hidden
#if($record.get("field name") = value)
$record.put("other field name", value)
$record.put("yet another field name", other value)
#else
$record.put("other field name", alternative value)
$record.put("yet another field name", other alternative value)
#end
In this case the return variable does not have to be set, because it is without meaning.