View source | View content page | Page history | Printable version   






Currently the user can only link a field to a direct database column of the table of the tab. However, there are cases where the user would also like to add computed properties to a grid/form (as display field) and would also want to filter/sort using these columns. The sorting and filtering is done in the database, this means that the computed property needs to be expressed using a HQL query. This proposal outlines the changes necessary for implementing a HQL Expression Field.

This development is related to other developments (see resources below) which also 'break' the strict relation between ad_field and ad_column:

Feature overview

Users & use cases


The development is a combination of changes in the application dictionary, the query mechanism and the json serializer.

If a HQL expression is entered then it is not necessary to set the ad_column value in ad_field. Therefore 2 other columns have to be added to ad_field:

The hql expression is executed by the datasource and the result is added to the json object. Filtering and sorting should also be possible.

The complexities of the development are:

Technical specification

Model Changes

Add 3 news columns to AD_Field:

Server side changes

Datasource querying

The datasource querying needs to be adapted to allow passing in one or more named hql expressions. In correspondence with the extra properties parameter used for the data source, the proposal is to add a new parameter which is handled by the datasource querying: hql expressions. The idea is to encode the hql expressions as json:

quantitySum: 'select sum(e.quantity) from OrderLine e where 

The name of the json property is the alias used in the hql query and it is the alias used for passing in filter and sorting parameters.

When a datasource is generated for a tab the fields with hql expressions need to be collected. The HQL expressions should be encoded as json and passed on to the datasource java script creator to be added as a parameter in the datasource requests to the server.

The same expressions should also be re-computed when inserting/updating an entity.

The generation of the datasource javascript is done through the OBViewTab.getDataSourceJavaScript method which uses the DataSourceComponent.

To support retrieval, filtering and sorting for expression properties the following needs to be changed:

Inserting/Updating an Entity

When an entity is updated or inserted the full entity is returned as json from the server to the client and is used by Smartclient to update internal caches. This is great functionality as it allows the server to make changes to the data while inserting/updating and make those changes visible in the client.

The same feature should be used to support recomputing expression properties when inserting/updating. The challenge is that expression properties need to be executed as part of a hql query and insert/update is not done through hql. The following solution is therefore proposed:

Field generation

The new expression properties should be generated as display only fields (type is OBStaticTextItem). This change is needed in the templates and related components in the org.openbravo.client.application.templates/windows packages.

Client side changes




This feature development is tracked using the following issue(s): to-be-added



The expression field should be illustrated using a howto showing an example of a display only expression field.


Retrieved from ""

This page has been accessed 2,338 times. This page was last modified on 8 June 2012, at 05:27. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.