Axelor Doc

Fields feature

Fields have a value calculated based and are typically read-only. Two types of function fields are available:

  • Fields defined functions with code java / groovy: Virtual Columns
  • Fields defined functions natively specific SQL Database used: Formula fields

Virtual Columns

Virtual Columns
<string name="label" namecolumn="true" search="code,name,company">
    <![CDATA[
    if(company != null)
        return code+"_"+ company.getCode() + " - " + name;
    else
        return code+" - " + name;
    ]]>
</string>

Virtual Columns are generally not concerned about the persistence because they are calculated. However, since they would not be so available for SELECT queries, the Axelor platform, the default backup.

Formula fields

Formula fields
<string name="fullName" namecolumn="true" search="firstName,lastName" formula="true">
    CASE
        WHEN title IS NULL THEN first_name || ' ' || last_name
        ELSE (SELECT contact_title.name FROM contact_title WHERE contact_title.id = title) || ' ' || first_name || ' ' || last_name
    END
</string>

The formula field if used in a query such as SELECT is accessible through the generated code below:

SELECT
    (CASE
        WHEN title IS NULL THEN first_name || ' ' || last_name
        ELSE (SELECT contact_title.name FROM contact_title WHERE contact_title.id = title) || ' ' || first_name || ' ' || last_name
    END) AS fullName,
    email AS email,
    phone AS phone
FROM
    contact_contact
WHERE
    ...
ORDER BY fullName

Since the SQL definition is used in the request, it is independent of the existence of the field in the database. The advantage of a formula field is the SQL query runs faster than Java method. The downside is that the field must be defined not portable native SQL, not JPQL.

A function field defined in Java or Groovy should contain only operations on strings or simple arithmetic, or a reference to a particular field of a relationship (many-to-one, for example) field. No request JPA is permitted.