For detailed information on all function parameters see read
in API Reference.
Function
🔎 Best Practice
Outsource the following modules via
sap.ui.define
:
/** * @description OData Service Read EntitySet Call * @returns {promise} oData Service Call * @private */ _readEntitySet: function() { var oServiceModel = this.getOwnerComponent().getModel(); return new Promise(function(fnResolve, fnReject) { var sPath = "/EntitySet"; var oParameters = { urlParameters: { "$expand": "toEntityB" //just as an example how we can pass urlParameters }, filters: [ new sap.ui.model.Filter({ //just as an example how we can pass filters path: "PropertyA", operator: sap.ui.model.FilterOperator.EQ, value1: "1" }) ], sorters: [ //just as an example how we can pass sorters new sap.ui.model.Sorter({ path: "PropertyA", descending: false }) ], success: fnResolve, error: fnReject }; oServiceModel.read(sPath, oParameters); }); }
Example
this._readEntitySet().then(function(oResponse) { //process response }.bind(this)).catch(function (oError) { //process error }.bind(this));
Related Information
For a more modern coding see the following blog post: Best practice approach for processing OData requests in JavaScript