Search code examples
hqlopenbravo

How to add distinct to filter expression in Defined Selector in Openbravo?


The filter expression which I am using now is,

"e.contract= '" +OB.getParameters().get('subscriptionId') + "'"

Here, e is the current table which is populated in 'Table' , and contract is the column there (In the POJO class) which stores the value of subscriptionId.

The issue is the attribute in the next level Defined Selector Field ,which I display a certain column exColumn has many rows [selected from the above expression] with same value.

Here , I intend to add a distinct in the filter expression or in the HQL [which doesn't seem to be filtering at run time] or in the Defined Selector Field, so that we don't display repeated values.


Solution

  • You cannot add distinct in a Filter Expression, which is used to restrict the results of the datasource.

    You have 2 different options:

    1. Define the selector based on a Custom Query and write there the HQL to retrieve the values. In this query you can have the distinct. As example you can check Business Partner not filtered by default by customer/vendor selector which is implemented in this way.
    2. Base your selector on a Table from a view:
      • Create a database view with the base SQL query you need including the distinct.
      • Register it as an Application Dictionary Table
      • Base your selector on it