on 2019 Feb 21 11:12 AM
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 Sascha Weidlich,
When I was checking your scenario, I found the below two things:
1. SAP UI5 doesn't support searching the associations of cardinality 1..* it only supports 1..1. So you cannot check the items but we can check the sales orders based on the business partner country (1..1) like the example given in the help.
https://help.sap.com/doc/saphelp_nw75/7.5.5/en-US/17/d5ee74dd4e4e8f802aaf4fdd51fbc6/frameset.htm

2. So I went a head and tested the odata service directly by sending the filter for the items. But that returned an error.
Left hand expression of memberaccess operator has wrong cardinality (to many not allowed)
So i guess only 1..1 cardinality search is supported.
BR,
Mahesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mahesh Kumar Palavalli,
thanks for your Input, this lead me to the right direction. 🙂
You're right, at the moment the "Fiori Element"-Concept doesn't support the "to many"-cardinality.
However, i found a "sneaky" workaround to achieve my requirement. See the following code:
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
association [0..1] to ZCDS_C_SalesOrderItems_00 as _VHItems on _Items.SalesOrderUUID = SalesOrder.SalesOrderUUID
{
....
_Items,
_VHItems
}<br>With a second association (and wrong cardinality, which leads to an warning) the filter will appear in the SmartFilter-Bar.
Thanks for your Help!
Regards,
Sascha
Awesome, didn't think in this direction. Super!!
One Question, I hope you are not getting any duplicate data?
This looks so intresting, I have to debug and see what exactly is happeing in the system 😛
BR,
Mahesh
I came to conclusion that if we do it with 1..1 cardinality data, it works fine else if it is by default 1..n and if we override it with 1..1, we will end up with duplicate data.. Not sure if any other approach is there though.
Thanks,
Mahesh
Not sure Susmitha Pritam Durai if it is possible,
But check if this approach is possible or not, use amdp and table function and concatenate multiple item rows column into single column using string aggregate function and maybe whatever the user selects from the UI, you could use contains and filter that out? Not sure if it will work though.
martin.s5 susmitha_pritam Sascha Weidlich sunil1101
You can use the below blog as reference to do this using virtual elements
Or you could use table function to concatenate all the searchable fields into one line using string_aggr function and use "Contains" filter to search from the UI.
Thanks,
Mahesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sascha, I was wondering about the results of your "sneaky" workaround 😉 are you using CDS based oData? Does the filtering work?
Best regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 |
|---|---|
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 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.