Sunteți pe pagina 1din 3

ODataModel.

read: pass select and filters

Oliver Ester 3 posts since Mar 18, 2015


ODataModel.read: pass select and filters Jun 27, 2015 1:10 PM
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
Tags: parameter, odata, select, read, filters

Sarath Chandra 148 posts since Oct 1, 2009


Re: ODataModel.read: pass select and filters Jun 27, 2015 2:52 PM
// 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) {

Generated by Jive on 2015-12-15+01:00


1

ODataModel.read: pass select and filters

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.

Oliver Ester 3 posts since Mar 18, 2015

Generated by Jive on 2015-12-15+01:00


2

ODataModel.read: pass select and filters

Re: ODataModel.read: pass select and filters Jun 27, 2015 3:44 PM
Perfect, thanks for your help!

indrajith patel 351 posts since Nov 10, 2014


Re: ODataModel.read: pass select and filters Jun 27, 2015 3:33 PM
Maybe this helps.
Filter Support for (sap.ui.model.odata.ODataModel).read(...) Function

Generated by Jive on 2015-12-15+01:00


3

S-ar putea să vă placă și