cancel
Showing results for 
Search instead for 
Did you mean: 

ODataModel.read: pass select and filters

Former Member
0 Kudos

Hi!

How is it possible to pass a select parameter and filters to the ODataModel.read function?

I found this example in the SAP help:

oModel.read('/Products(1)', null, null, true, function(oData, oResponse){

  alert("Read successful: " + JSON.stringify(oData));

  },function(){

alert("Read failed");});

However isn't it contracdicting to the API?:
JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.odata.ODataModel

Thanks for your help!
Oliver

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

// Creating a filter object so preparing arrays for Ids and Values separately.

aFilterIds = ["sProductId"];  

aFilterValues = [sProductIdValue];

// once the Id and Values are prepared separately, dynamically prepare the filter object by calling below method.

aFilters = this._createSearchFilterObject(aFilterIds, aFilterValues);

//Build the Parameters required for the Read method.

var mParameters = {

                filters : aFilters,

                 urlParameters:{"$select" : "Category,ProductName", "$expand" : "Category" }

                success : function (oData) {

                    jQuery.sap.log.info("Odata Read Successfully:::");

                }.bind(this),

                error: function (oError) {

                    jQuery.sap.log.info("Odata Error occured");

                }.bind(this)

            };

// As the parameters is build, start calling read method with sPath and mParameters.

            if (oModel) {

                oModel.read(sPath, mParameters);

            }

// method to create different filters.(modify according to ur requirement.)

       /**

  * Assign the filter objects based on the input selection

  *

  * @function

  * @param {Array} aFilterIds to be used as sPath for Filters

         * @param {Array} aFilterValues for each sPath

  * @private

  */

        Controller.prototype._createSearchFilterObject = function (aFilterIds, aFilterValues) {

            var aFilters = [],

                iCount;

            for (iCount = 0; iCount < aFilterIds.length; iCount = iCount + 1) {

                aFilters.push(new Filter(aFilterIds[iCount], FilterOperator.EQ, aFilterValues[iCount], ""));

            }

            return aFilters;

        };

Hope this helps.

Thanks.

Sarath.

Former Member
0 Kudos

Perfect, thanks for your help!

Answers (1)

Answers (1)

Former Member
0 Kudos

Maybe this helps.