Calculation helpers

Calculations are helpers that determine a value of a field, based on the value of other fields. Calculations are like formulas in a spreadsheet.

How to use a calculation helper

A calculation is always defined as a property of the field which value has to be calculated. As a result of this, the field will automatically become a read-only field. If the result of the calculations should always be defined at run time in the application, no database column name should be entered for the field. If the result of the calculation should be stored in a persistent manner however, the field must have a database column.

You can set the calculation at the tab Properties. Select a calculation helper and it will be possible to edit it's parameters. In this screen, source fields can also be set. Whenever these fields' contents are changed in the application, the calculated field will be automatically recalculated.

Example: Field concatenation

Suppose, we want a field full name for a person. The full name will be a combination of the first name and last name fields.             

  • Create a new field "full name"
  • Go to the tab Properties in the field details of this new field
  • Select the type Field concatenation as calculation type in the "helper" section.
  • Click "Edit parameters".
  • Add fields by clicking the "add fields" button, followed by the "select field route" button.
  • Put a space in the "prefix" field of the last name.
  • Click "ok" and save.

This will create a new field for your class containing the full name for a person.

 

 

Available calculation helpers

The following calculation types are standardly available in the Standard Application Engine:

  • Account info

    This calculation provides information about the status of the account. This calculation can only be defined for fields on a user class. A user class is a class that contains data about users of the application. The property 'Email field for account' should always be set.



  • Age

    This helper type is deprecated. An age can not be calculated with a calculation since the value should change automatically every year. Replace this helper by a daily job that checks and updates the age. Only if the calculation is not persistent, you can still create a velocity script that calculates the age as a calculation.

    You can use any of the example scripts below as replacement.

    velocity

    #set($birthDate = $record.get('birthdate'))
    #set($today = $application.newDate())
    #set($return = $engine.getDateOps().getDifferenceInYears($birthDate, $today))

    javascript

    const TimeUnit = Module.import("crossmarx.value").TimeUnit;
    let birthdate = record.get(Classes.client.Birthdate);
    if (birthdate) {
            return birthdate.getDifference(Date.today(), TimeUnit.YEARS);
    }

    gravel

    #set($TimeUnit = $Module.import("crossmarx.value").TimeUnit)
    #set($birthdate = $record.get($Classes.client.Geboortedatum))
    #return($birthdate.getDifference($Date.today(), $TimeUnit.YEARS))



  • Autonumber

    This helper type is deprecated. In case you need help in updating your helpers, contact CrossmarX by filing an issue. 

    This component returns a number that is calculated as the maximum number plus 1, within a group. Usually a group is a connected table. Example use: an invoice has invoice items. Every invoice item should have unique numbers, starting from 1. This helper can be best replaced by the class trigger Autonumber.

     



  • Confirmation status

    This calculation provides information about the status of the confirmation process. The status can have three values: 'pending' (awaiting confirmation), 'partially confirmed' and 'confirmed'. For this calculation to be usefull, you will need to allow the use of confirmation services in your application and implement the confirmation action helper as well.



  • Email from account
    This calculation provides the validated email address from the account. This calculation can only be used for fields that belong to a user class.

  • Expression

    Calculates the value of a field using an expression.
    An expression is any combination of operators, constants, functions and names of fields that evaluates to a single value.



  • Field concatenation

    This calculation helper can be used to concatenate the values of different fields. Each field can have its own prefix and postfix.



  • First value getter

    This calculation retrieves the value from another field. More than one field may be specified. The value getter will return the first value that is not null.



  • Full name

    This helper type is deprecated. In case you need help in updating your helpers, contact CrossmarX by filing an issue. 

    Creates the full name for a person.

    This helper is deprecated. The Helper Type Field Concatenation can be used instead.



  • Gross amount

    This helper type is deprecated. In case you need help in updating your helpers, contact CrossmarX by filing an issue. 

    Calculates the gross amount from a net amount and a value added tax amount. VAT can also be expressed as a decimal number or percentage.

     



  • JAVA plugin helper
    A calculation implemented in a JAVA class file. This option is not available yet for external developers. CrossmarX can program the calculations in the mean time. If you want to develop the calculation your self, please use Velocity.

  • Latitude

    This helper type is deprecated. In case you need help in updating your helpers, contact CrossmarX by filing an issue. 

    Returns a latitude value based on a postal code and house number. Works only for Dutch addresses.



  • Lock status

    This helper type is deprecated. In case you need help in updating your helpers, contact CrossmarX by filing an issue.



  • Longitude

    This helper type is deprecated. In case you need help in updating your helpers, contact CrossmarX by filing an issue. 

    Returns a longitude value based on a postal code and house number. Works only for Dutch addresses.



  • Multiplication

    This helper type is deprecated. In case you need help in updating your helpers, contact CrossmarX by filing an issue.



  • Net amount

    This helper type is deprecated. In case you need help in updating your helpers, contact CrossmarX by filing an issue.

    Calculates the net amount from a gross amount and a value added tax percentage. 



  • PDF generator

    This helper type is deprecated. In case you need help in updating your helpers, contact CrossmarX by filing an issue. 

    Generates a PDF from a velocity HTML template.



  • Script

    This calculation helper type allows you to define the calculation of a field using a script.



  • Simple concatenation

    This helper type is deprecated. In case you need help in updating your helpers, contact CrossmarX by filing an issue. 

    This component concats the content of fields with a separator.

    This helper is deprecated. The Helper Type Field Concatenation can be used instead or you can create your own script. Example below concatenaties a full address from several fields.

    javascript

    let street = record.get(Classes.address.Street);
    let number = record.get(Classes.address.Number);
    let extra = record.get(Classes.address.Extra);
    let zipcode = record.get(Classes.address.Zipcode);
    let city = record.get(Classes.address.City);
    let values = [street, number, extra, zipcode, city];
    let s;
    for (let value of values) {
        if (value) {
            if (!s) {
                s = value;
            } else {
                s += " " + value;
            }
        }
    }
    return s;

     



  • Street and city

    This helper type is deprecated. In case you need help in updating your helpers, contact CrossmarX by filing an issue. 

    Calculates the street and the city of an address from a zip and number by calling a webservice from Cendris.



  • Value added tax

    This helper type is deprecated. In case you need help in updating your helpers, contact CrossmarX by filing an issue. 

    Calculates the value added tax from the net amount and a value added tax percentage.



  • Value from neighbour

    With this calculation one can retrieve the value or values of a field from one or more related records and use these in an aggregate function. The function sum can be used to add up the values, if the values 3,8 and 4 are retrieved this function will return 15. The function count calculates the number of values what will return 3. 

    For example the class Person has a relation with the connected class order. The class order has the field Total gross amount and now we can use the values of this field in the class Person . Sum will add up the Total gross amount values and count will calculate the number of Total gross amount values.



  • Velocity

    Allows you to write your own calculation in velocity.