on 06-27-2015 12: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
// 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.