cancel
Showing results for 
Search instead for 
Did you mean: 

MDK Filter Action with List Picker for a concatenated value attribute in related service

eduardo_espinosa
Explorer

Hi Team.

I am working on an MDK app trying to apply some filters automatically inherited from a List Picker a in Filter Page called from a Filter Action related to a Filterable Object table.

It is working as expected for List Pickers in which the property is a direct value.

For example:

FilterProperty: "COUNTRY_ID"

Generated filter for OData service / entity: "$filter=COUNTRY_ID eq 'US'"

But we have currently one scenario when we have an attribute in the related OData service / entity that has concatenated values.

Example of Attribute Value: TAG_CONCAT = 'H00002,H00035,H00435,H00878'

If at the List Picker we set the FilterProperty in the following way:

FilterProperty: "TAG_CONCAT"

The generated filter for OData is something like: "$filter=(TAG_CONCAT eq 'H00035' or TAG_CONCAT eq 'H00878')"

Which in most of the cases won't retrieve the required row.

The solution for this case (implemented in the equivalent app in Fiori / Web ) is using the "substringof" OData function in order to have a condition like the following:

"$filter=(substringof('H00035',TAG_CONCAT) or substringof('H00878',TAG_CONCAT))"

I have tried in this way in the List Picker:

FilterProperty: "substringof(<TAGID>,TAG_CONCAT)"

But is generating a filter like:

"$filter=(substringof(<TAGID>,TAG_CONCAT) eq 'H00035' or substringof(<TAGID>,TAG_CONCAT) eq 'H00878'))

and is not working.

I have already investigated some places in order to try to override or change the generated filter, so I can fix it and keep the List Picker functionality, and in general, the Filter Page functionality, but without success.

Also I have tried to add some filters in the Query Options of the Object Table direclty, but it seems that if it is already related to a "Filterable" object in the action, the filter in the QueryOptions is discarded.

Please comment what are the possible options or workarounds in this case.

Thanks in advance, your help is appreciated.

Best Regards

Eduardo

Accepted Solutions (1)

Accepted Solutions (1)

bill_froelich
Product and Topic Expert
Product and Topic Expert

You can still use a Filter Action if you want your custom filter page to display the same way the standard filer page displays. Setting the current filter in the OnLoaded is how I would do it. Here is an example for my custom filter.

I get the picker value to store by calling the following and storing the yearFilter to Client Data in the previous page

let yearFilter = clientAPI.evaluateTargetPath('#Page:CustomFilter/#Control:YearPicker/#Value');

Because I allow multiple selections from my list picker, the value I set in the OnLoaded to the control needs to be an array of the return values. Since my array that I stored in Client Data contains the Return Values and Display Values, I need to construct an a new array of the return values to set to the picker.

export default function SetFilterDefaults(context) {
  let prevPage = context.evaluateTargetPathForAPI('#Page:-Previous');
  let clientData = prevPage.getClientData();
  let yearFilter = clientData.yearFilter;
  let yearPicker = context.evaluateTargetPathForAPI('#Page:CustomFilter/#Control:YearPicker');
  if (yearFilter && yearFilter[0]) {
    let selected = [];
    for (let i=0; i < yearFilter.length; i++) {
      selected.push(yearFilter[i].ReturnValue);
    }
    yearPicker.setValue(selected);
  }
} 
eduardo_espinosa
Explorer
0 Kudos

Hi Bill.

By sending only the JSON array with the return values at the setValue() function solved the issue.

About using the Filter Action, initially I tried using it but it forces me to assign a Filterable Object (In this case the related Object Table in the List Page). That was avoiding to influence the behavior of the query at the related QueryOptions rule. In fact I tried to use a dummy Object Table at the Main page for that Filterable object, but there it was never passing the on filter success action. Finally I implemented this with a normal navigation action and works well.

Thanks for the quick responses and all your help.

Best Regards

Eduardo

--- Additional comment:

The reason that we did not use the Filter Action is due that at the Query Options is not working for us, only in iOS, the DataQueryBuilder() (not able to avoid default MDK search) when we have a service which entity supports parameters, like the following:

/<service>/InputParams(<PARAMETER>='')/Results

This entity was created with an "xsodata" artifact in Hana backend.

I hope and I would appreciate if you can review it in order to avoid some workarounds implemented by us.

Thanks and Best Regards

Eduardo

Answers (1)

Answers (1)

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Eduardo,

In this case the automatic filters will not work for you. The filter action currently only supports an exact match to the specified field. We have an enhancement on the roadmap to support data query builder for filters but until that is available you will need to implement your own custom filter as a workaround.

In your filter page you will want to not map the list picker as a return and instead store the selected values probably in client data on the previous page (your list page). On your list page you will need to write a rule for the query options to check for the stored filter value and parse and apply based on your custom logic (applying as substrings in this case) to the query options.

You will be able to achieve the same essential behavior of the filter through the use of some additional rules.

—Bill

eduardo_espinosa
Explorer
0 Kudos

Thanks Bill.

I followed your recommendation and I have already implemented a Page with List Picker (Without a Filter Action for arriving to it) and I am passing to the related clientData of the Page with the Object Table to be filtered the List Picker values obtained with the getValue() function of the control, and is working as expected.

The current issue is when I navigate back to the Filter Page with the List Picker. I want to populate the List Picker in the OnLoaded event of the page with the setValue() function of the related control, but is not working so far (Attached screenshot of the code at OnLoaded).

Currently I am passing the JSON object "as is", with the value obtained with the "getValue() (Attached the value tried to be set at setValue())

Should the setValue() parameter be different? Is this OK and a redraw() of the control or something else needed?

I have put the code in the "OnLoaded" event of the page, but I don't know if at somewhere else is needed.

Thanks in advance for your comments.

Best Regards

Eduardo