Hi folks,
im facing a strange Problem in the "ListReport" of the Fiori Elements and hope you can help me to fix my issue. 🙂
My requirement is to provide some filter-options for the starting Table based on an association. (for example the List shows some SalesOrder Headers and on the Object Page also the SalesOrder Items are provided. And now the User wants just to see the SalesOrder Headers where an Item is included with the Product "XY")
After looking into the CDS-Help i thought that the following Code would work:
define view ZCDS_C_SalesOrder_00
as select from ZCDS_I_SalesOrder_00 as SalesOrder
association [0..*] to ZCDS_C_SalesOrderItems_00 as _Items on _Items.SalesOrderUUID = SalesOrder.SalesOrderUUID
{
....
@UI.selectionField: [{ element: '_Items.Product', position : 2 }]
_Items,
}
But unfortunately the Filter for the Product is still not visible in the Filterbar, even under "more Filters".
The CDS-Help (Link to Help) says for UI.selectionField.element the following:
Must be used when an association is annotated, the value is a path to an element of the associated view. You use this option if you want to filter a table for a column that is not defined in your CDS view but in another CDS view.
Example:You define a sales order view in which you want to filter business partners for their country of origin. However, these country information are not maintained in the sales order view but in the business partner view.
So i thought this is exactly what im looking for, but it seems not. 😄
Has anyone an idea how to achieve the requirements with CDS Annotations?
As always any kind of informations is appreciated.
Thanks for your help!
Sascha
Request clarification before answering.
Hi everyone,
I stumbled upon this question because I had a very similar requirement: adding a filter on the list report page for a property of a child entity (i.e. filtering on an associated entity with a one-to-many cardinality). In my RAP BO and Fiori Elements app, I eventually managed to solve this using a virtual element with a custom filter.
In the implementation of the filter transformation method (if_sadl_exit_filter_transform~map_atom), I selected all entries from the child entity where the relevant field contains the filter value (iv_value). Next, I looped over the retrieved entries and, for each one, created a condition on the field used to match the association between the parent and the child. (In my scenario this is also the unique key of the parent entity, so I could directly filter on this field, but perhaps there are some use cases where it is necessary to first obtain the corresponding entries of the parent entity). I then chained these individual conditions together using the OR operator, as explained on this SAP Help page. Finally, I added a fallback condition to handle the case when no matching entries are found, ensuring that the filter is never empty.
Below is a generic code sample where you can replace the placeholders (e.g. <your_child_entity>, <matching_field>, <parent_key>, and <filter_field>) with your actual names.
I hope this solution will help anyone else with the same requirement!
METHOD if_sadl_exit_filter_transform~map_atom.
DATA lt_child_entries TYPE TABLE OF <your_child_entity>.
DATA ls_child_entry TYPE <your_child_entity>.
DATA lo_field_filter TYPE REF TO if_sadl_simple_cond_element.
DATA lo_condition TYPE REF TO if_sadl_cond_provider_generic.
" Get all entries from the child entity where <filter_field> equals iv_value
SELECT <matching_field> FROM <your_child_entity>
WHERE <filter_field> = @iv_value
INTO TABLE @LT_child_entries.
LOOP AT lt_child_entries INTO ls_child_entry.
" Create a condition for the parent entity key field
lo_field_filter = cl_sadl_cond_prov_factory_pub=>create_simple_cond_factory( )->element( '<parent_key>' ).
lo_condition = lo_field_filter->equals( ls_child_entry-<matching_field> ).
" Chain conditions with OR
IF ro_condition IS INITIAL.
ro_condition = lo_condition.
ELSE.
ro_condition = ro_condition->or( lo_condition ).
ENDIF.
CLEAR lo_field_filter.
ENDLOOP.
" Fallback: If no conditions were created, apply a default condition
IF ro_condition IS INITIAL.
lo_field_filter = cl_sadl_cond_prov_factory_pub=>create_simple_cond_factory( )->element( '<parent_key>' ).
ro_condition = lo_field_filter->equals( '' ).
ENDIF.
ENDMETHOD.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In my case, having this in my cds interface view:
I just added this in my metadata extension of the consumption view:
and everything worked as expected!
| User | Count |
|---|---|
| 5 | |
| 5 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.