Reputation: 111
I am using SAP UI5, and was trying to fetch some data from a public odata service.
I making the call in the following code snippet.
matched:function(oEvent){
if(!sap.ui.getCore().getModel("emp"))
{
var url = this.getOwnerComponent().getMetadata().getConfig().service.url
console.log("url")
console.log(url)
var oData = new sap.ui.model.odata.ODataModel(url,true)
oData.read("/People?top=5",{
async:true,
success:function(oData,response){
var eModel = new sap.ui.model.json.JSONModel();
eModel.setData(oData);
sap.ui.getCore().setModel("emp", eModel)
}
And I have configured the service url in Component.js like so..
config : {
resourceBundle : "i18n/messageBundle.properties",
service:{
url:"http://services.odata.org/V4/TripPinServiceRW"
}
As soon as the oData.read() method is called an uncaught error is thrown.. from js files in resources folder.
I checked the network tab in the browser , each time oData.read() is called I see 4 calls being made
1.http://services.odata.org/V4/(S(d1goo34fnpbdpleuuykeha2r))/TripPinServiceRW/$metadata
2.http://services.odata.org/V4/(S(pgzb5mtb0yp5ytw25xrdfcxl))/TripPinServiceRW/$metadata
3.http://services.odata.org/V4/TripPinServiceRW/People?top=5
4.http://services.odata.org/V4/(S(zobeyavqtqtykfyyj1m4jqrt))/TripPinServiceRW/People?top=5
Except for the third all others return status 200 , the third one returns status 302.
The last request does return data , but the query doesn't work, instead of top 5 all the records are being fetched.
I would like to know if I am doing anything wrong , any sort of help is appreciated.TIA.
FYI the version for UI5 is 1.34.9
Also I had tested the public service using postman , it was working fine.
Upvotes: 0
Views: 1241
Reputation: 11
OData-MaxVersion
. If the service can provide a response compliant with that version, it will.top
not working: Please note that according to the OData Spec V2 the query option is named $top
, not just top
.So just try:
var oData = new sap.ui.model.odata.ODataModel(url,true)
oData.setHeaders({
"OData-MaxVersion": "2.0"
});
oData.read("/People?$top=5", {
async:true,
success:function(oData,response) {
// ...
}
}
Upvotes: 0