Skip to content
Advertisement

UI5 Odata read call with filter and urlParameters simultaneously

Hi I am trying to call Odata read with filter and parameters. But not able to get the data back. Any inputs would be appreciated

            var fWerks = new sap.ui.model.Filter({
                path: "Werks",
                operator: sap.ui.model.FilterOperator.EQ,
                value1: vWerks
            });

            var fIblnr = new sap.ui.model.Filter({
                path: "Iblnr",
                operator: sap.ui.model.FilterOperator.EQ,
                value1: iIblnr
            });

            var oFilter = new Array();
            oFilter.push(fWerks);
            oFilter.push(fIblnr);
            
oModel.read("/PIHeaderSet)", {
    filters: [oFilter],
    urlParameters: {
        "$expand": "PIHeaderToItemNav"
    },
success: function(oData, response) {
                oModelJson.setData(oData);
                sap.ui.getCore().setModel(oModelJson, "oJSONModel");
                // alert("Success!");
    
            },
            error: function(response) {
    
            }
});         

Advertisement

Answer

try removing the square brackets around oFilter in your code:

filters: [oFilter],

should be replaced by

filters: oFilter,

the filters attribute expects an Array of sap.ui.model.Filter. Your oFilter variable is already an array of Filter-objects, therefor there is no need to put oFilter between square brackets.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement