Quantcast
Channel: SCN : All Content - SAPUI5 Developer Center
Viewing all articles
Browse latest Browse all 6178

OData remove method error (TypeError: object is not a function)

$
0
0

Hi, I tried to delete records from the Travel Agencies SAP OData service, but I get an error after de record was delete successfully.

The error in google chrome console is: Uncaught TypeError: object is not a function

 

 

This is the relevant code in index.html

 

//var sServiceUrl = "proxy/https/sapes1.sapdevcenter.com/sap/opu/odata/IWFND/RMTSAMPLEFLIGHT/";
var sServiceUrl = this.getUrl("/sap/opu/odata/IWFND/RMTSAMPLEFLIGHT/");
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true, "user", "password"); //sServiceUrl, bJSON, sUser, sPassword
sap.ui.getCore().setModel(oModel);

 

This is the relevant code in controller.js

 

 

deleteFlights: function(oTable){     jQuery.sap.require("sap.m.MessageBox");     if(oTable.getSelectedItems().length==0){          sap.m.MessageBox.show("Debe seleccionar al menos un vuelo para eliminar", {icon: sap.m.MessageBox.Icon.INFORMATION, title: "Vuelos"});     return;     };     for (var i=0; i < oTable.getSelectedItems().length; i++){          var agencyNum = oTable.getSelectedItems()[i].getBindingContext().getProperty("agencynum");          var name = oTable.getSelectedItems()[i].getBindingContext().getProperty("NAME");          oModel.setHeaders({"content-type" : "application/json;charset=utf-8"});          oModel.remove("/TravelAgencies('" + agencyNum + "')", null, {                              success : jQuery.proxy(function() {                    jQuery.sap.require("sap.m.MessageToast");                    sap.m.MessageToast.show("el Vuelo '" + name + "' se elimino con exito.");               }, this),                              error : jQuery.proxy(function(mResponse) {                    var body = mResponse.response.body;                    var res = body.split(",");                    console.log(res);                    sap.m.MessageBox.show("Se produjo un problema eliminando el vuelo.", {icon: sap.m.MessageBox.Icon.ERROR, title: "Vuelos"});               }, this)          });     }
},

 

After execute the above code, the record is deleted from SAP (because when I refresh the data, the record doesn't exists anymore) but throws the following error: Uncaught TypeError: object is not a function

 

I tried to debug de code and expects it stop in error: callback breakpoint, but, after execute oModel.remove, the record is deleted and the debugger is stop automatically with the error mentioned above.

 

 

I tried to do this with another OData service, http://services.odata.org/V2/(S(sapuidemotdg))/OData/OData.svc, and the results was exactly the same.

 

it will be a bug of remove method?

 

Regards,


Viewing all articles
Browse latest Browse all 6178

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>