Skip to Content
0

UI5 OData Remove/Delete callback

Nov 11, 2016 at 04:45 PM

175

avatar image

Hi Gurus,

i'm facing a little problem during the implementation of Remove method for OData models

i implemented the following code and if everything is succesful the callback is triggered.

Sadly, when something wrong occurs (i.e. i get a 400 or a 500 response), the error callback is not triggered at all

 var oModel = new sap.ui.model.odata.v2.ODataModel(
         self.BASE_URL + serviceName + "/",
         {
           user: self.user,
           password: self.password,
           headers: headers
         }
       );
       oModel.setUseBatch(false);
       oModel.attachMetadataFailed(null, function(){
           var resp  = {
             status: 418,
             message: "Error in retreiving model metadata"
           }          
         },
         null);
       oModel.attachMetadataLoaded(null, function(){
         var callbacks = {
           success: function (oData, oResponse) {
             console.log('success');
             
           },
           error: function (oResponse) {
             console.log('error');
             
           }
         };

var uri = "/" + entityName + ("(" + id + ")");
         oModel.remove(uri, item, callbacks);
 }, null);

Do you have any idea about why it's wrong?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Simone Milesi Nov 14, 2016 at 07:48 AM
0

My shame.

The call was dynamic (for Create/Update/Delete) so i always passed even the Object.

Delete does not want it.

Share
10 |10000 characters needed characters left characters exceeded
Nils Lutz Nov 12, 2016 at 09:04 AM
-1

if im not wrong you only catch errors on failed metadata loaded. you have to implement own callbacks for the odata remove function.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

No, if metadata are loaded (so the connection is ok and the model is created), i fill callbacks variable which stores the 2 functions SUCCESS and ERROR.

In fact, as i stated, in case of successful deletion, the SUCCESS callback, created this way, is triggered.

0