Skip to content

How to filter data in a reference

filter in dependence of the value of a field of the same model

The feature is implemented by the FilterBy node as in the following example from a real project (The user first selects the Customer and then the invoice):

yaml
ModelName: Payment
Fields:
....
  Customer: Reference(Customer) not null
    PhysicalName: FK_PAGAMENTO_CUSTOMER
    Fields:
      Customer_Id:
        PhysicalName: CUSTOMER_ID
  Invoice: Reference(Invoice) not null
    Fields:
      Fattura_Id:
        PhysicalName: INVOICE_ID
    FilterBy:
      Customer: Customer

filter in dependence of other values

The feature is implemented by the LookupFilter node as in the following example from a real project (activities are filtered in accordance to current user):

yaml
ModelName: Activity
Fields:
  Employee: Reference(Employee) not null
    PhysicalName: FK_ACTIVITY_EMPLOYEE
    DisplayWidth: 10
    LookupFilter: (EMPLOYEE_ID = '%Auth:EMPLOYEE_ID%')
    Fields:
      Employee_Id:

filter a detail's reference by the master record ({MasterRecord.*})

In a master-detail form, a reference field on the detail can be filtered by a value of the master record currently being edited, using the {MasterRecord.<FieldName>} macro inside LookupFilter (or DefaultFilter). The detail form's store is linked to the master record in session, so the macro is resolved when the lookup opens; the dedicated lookup grid applies the same filter during search and paging.

yaml
ModelName: OrderDetail
Fields:
  Product: Reference(Product) not null
    # only products of the supplier chosen on the master order
    LookupFilter: (SUPPLIER_ID = '{MasterRecord.Supplier_Id}')
    Fields:
      Product_Id:

Released under Apache License, Version 2.0.