cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How does RAP obtain the values in the filter box?

lqj111
Discoverer
0 Likes
3,184

I want to obtain the values in the page filter box and fill them in the corresponding positions on the creation interface. Is there any good way?

Accepted Solutions (0)

Answers (3)

Answers (3)

meenakshi-btp
Explorer
0 Likes

Were you able to implement it in behavior implementation class or was it achieved using frontend?

M-A-R-C
Explorer
0 Likes

https://sapui5.hana.ondemand.com/sdk/#/topic/189e2d8a59f04a2693a4fde7f4a91a65

Seems like this is a frontend feature. You have to activate "createWithFilters" in your ListReport and redefine the hook that passes the filter values to the create page:

"component": { 
    "name": "sap.suite.ui.generic.template.ListReport", 
     "list": true, 
     "settings": { 
        "createWithFilters": { 
            "strategy": "extension" 
        }
    } 
}, 
getPredefinedValuesForCreateExtension: function (oSmartFilterBar) { 
    const oSelectionVariant = oSmartFilterBar.getUiState().getSelectionVariant(); 
    const aSelectOptions = oSelectionVariant.SelectOptions; 
    const aRelevantProperties = ["UserName", "Telephone", "FullName"]; 

    const aRelevantFilterValues = aRelevantProperties 
        .reduce((oRes, sProp) => { 
            const oSelectOption = aSelectOptions 
                .find(o => o.PropertyName === sProp); 
            if (oSelectOption?.Ranges.length === 1) { 
                const [filter] = oSelectOption.Ranges; 
                if (filter.Sign === "I" && filter.Option === "EQ") { 
                    oRes[sProp] = filter.Low; 
                }
            } 
            return oRes; 
        }, {}); 
    return aRelevantFilterValues; 
}, <br>
meenakshi-btp
Explorer
0 Likes

Hi M S,

Mine is Managed scenario with oData v2, no draft.

I was able to activate "createWithFilters" in my ListReport. Now I see two dropdowns for the standard Create button- Create Object and Create with Filters.

However, I am not sure on how to redefine the hook that passes the filter values to the create page.

I do not see any option to define controller extensions on my Page Map.

I am very new to UI5 programming, so this could be a basic thing, but I am not able to get through it. Any pointers/references are greatly appreciated.

DiegoValdivia
Active Participant
0 Likes

Hi,

I'm not sure if there's a way to achieve this using only RAP code.

Though, I think this is possible using a controller extension:

First, get the FilterBar ID using UI5 Inspector.

In my case, I have the following filters:

And this is the Filterbar ID shown in the UI5 Inspector

Then implement an extension:

  1. Use Open Guided Development to create a custom button
  2. Add code to get the Filter bar Instance using this.byId()
  3. Get all Filter values using Filterbar method getFilterItems(). In my case, such method returns Created On filter:

  4. Use Extension API + method invokeActions to call a RAP Static Factory action to create your business object. Send the filter values as parameters
  5. Navigate to the newly created business object using Extension API + Navigation Controller

I hope this helps.

lqj111
Discoverer
0 Likes

Thank you for your answer ,Diego Valdivia, but I would rather implement it in the behavior implementation class.

rammel_sapdev
Participant
0 Likes
Hi @lqj111, have you resolved this issue?