cancel
Showing results for 
Search instead for 
Did you mean: 

oData v2 submitChanges Error Handling

Former Member
0 Kudos

Hi,

I'm having trouble with the calback functions of the submitChanges() method JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.odata.v2.ODataMod...

My code is as follows:


oDataModel.setUseBatch(true);

oDataModel.create("/SomeEntity", data, {

    "changeSetId": "create"

});

oDataModel.callFunction("/SomeFunctionImport", {

     "method": "POST",

     "changeSetId": "function"

});

oDataModel.submitChanges(function(oEvent){

     alert("Success");

}, function(oEvent){

     alert("failure");

});

The submitChanges call goes through without any problems. The problem is that the error/success handlers doesn't get called. The documentation has the following note:

"Important: The success/error handler will only be called if batch support is enabled. If multiple batchGroups are submitted the handlers will be called for every batchGroup."

But I am setting the Model to use batch?

Using the model's event handlers doesn't work because they get called for every request that my model make, I only want to handle the specific submitChanges() calls.

Regards

Accepted Solutions (0)

Answers (2)

Answers (2)

Attila
Active Participant
0 Kudos

Hi Albert,

as far as I know, the submitChanges sends changes by the setProperty method to the backend. If you call the create function directly for an entity, for which you defined no deferred batch groups, your create operation is sent immediately to the backend. After when calling the submitChanges there will be no callback bacause no changes to submit. You can check for pending changes using method hasPendingChanges method.

Regards

Attila

sebastianraemsch
Active Participant
0 Kudos

Hi Albert,

I think your syntax is wrong.

Please try:


oModel.submitChanges({

  success: function(oData){

  sap.m.MessageToast.show(oData.toString());

  },

  error: function(oError) { }

  });

Best regards,

Sebastian

Former Member
0 Kudos

Hi,

Thank you for the reply but unfortunately it did Not solve the problem

sebastianraemsch
Active Participant
0 Kudos

Hi Albert,

I don´t know what´s wrong. In my case it works.

Maybe already the "createEntry" call is wrong.As far as I see you set 3 parameters but createEntry has only 2.

Please try:


oModel.createEntry("SomeEntity", {

  properties: {

  yourProperty1: "a value"

  }

});

Best regards,

Sebastian

sebastianraemsch
Active Participant
0 Kudos

Sorry, I didn´t had a look at your first post closely. You use "create" and not "createEntry" and I gues that´s the issue. It doesn´t fit together.

Br, Sebastian

Former Member
0 Kudos

Hi,

Yes I think you're correct. I removed my submitChanges and it didn't change anything. The calls are still made without any problems.

So I guess I have to ask now how do I check if both my calls succeeded before I continue? (I think I should maybe open up a new thread for this?)

sebastianraemsch
Active Participant
0 Kudos

Hi Albert,

I guess you have to subscribe to events "requestCompleted" and "requestFailed". As you wrote the events will be fired for every request on your model. So maybe you have to attach the event directly before your request and detaching it directly after recieving the event(s). I tried somehing similar and basically it worked. But for me the "createEntry" and "submitChanges" solution seems to be better (first of all "clearer"). But maybe it´s not possible in your case.


Maybe other experts have a better solution.


Best regards,

Sebastian

Former Member
0 Kudos

Hi,

Yea Unfortunately I have to call the Function Import and the Create method in the same batch. I've tried setting the event handlers and then removing them as soon as they returned something (to stop other calls from interfering) but it unfortunately didn't work as well as I hoped it would.

Thanks again for the reply

sebastianraemsch
Active Participant
0 Kudos

Hi Albert,

I just came accross method attachEventOnce. It´s a member of object sap.ui.base.EventProvider and ODataModel object is an indirect subclass of this. So it should work on principle. I didn´t tested it but maybe this could solve your issue?

Best regards, Sebastian