cancel
Showing results for 
Search instead for 
Did you mean: 

oData submitChanges for new entry with result

h_senden2
Active Contributor
0 Kudos

hi,

i'm using the oData submitChanges method in my UI5 component.

In case of a new entry i want the result back, in particular the ID of the newly created entry.

How can i get this ID ?

My code looks like :

this.getView().getModel().submitChanges(

                          // OK

                         function(oData) {

                                       // oData undefined. Which data to get the newly created entry ID ?

                                       ....

                          },

                         // not OK

                         function() {

                                     ...

                          }

      

Any suggestions ?

gr Hans

Accepted Solutions (1)

Accepted Solutions (1)

sebastianraemsch
Active Participant

Hi Hans,

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

That depends on the oDataModel he's using.

sebastianraemsch
Active Participant
0 Kudos

No, I think the syntax error doesn´t depend on the oDataModel. I tried Hans´ coding and oData was undefined in my case too (and I´m sure I have a different oDataModel).

Former Member
0 Kudos

Yes it does. If you take a look at sap.ui.model.odata.ODataModel you'll see that the submitChanges function takes two anonymous functions (I had the problem once), but the sap.ui.odata.v2.ODataModel uses an Object with the functions error and success like you suggested.

SAPUI5 SDK - Demo Kit

v2

SAPUI5 SDK - Demo Kit

former_member182372
Active Contributor
0 Kudos

Nils is right, v(1) doesnt have parametrized argument

ODataModel.prototype.submitChanges = function(fnSuccess, fnError, oParameters)

v2 does

ODataModel.prototype.submitChanges = function(mParameters)

h_senden2
Active Contributor
0 Kudos

hi Sebastian,

i have tried it before with oData in the parameter set, but again oData was undefined

Former Member
0 Kudos

Can you show us the request with the payload as well as the response with their payload?

former_member182372
Active Contributor
0 Kudos

what about response (second parameter)?

sebastianraemsch
Active Participant
0 Kudos

Yes, ok. Sorry, I assumed that he´s using oDataModel v2 but it´s not menioned here...

Answers (3)

Answers (3)

h_senden2
Active Contributor
0 Kudos

It is working now. Only for a newly created entry the oData object was filled. For an existing one not.

TimMuchena
Participant
0 Kudos

This message was moderated.

former_member182372
Active Contributor
0 Kudos

* @param {function} [fnSuccess] a callback function which is called when the data has

*             been successfully updated. The handler can have the

*                             following parameters: oData and response.

oData should have a new key

Former Member
0 Kudos

That depends on your implementation of the odata service in your gateway. If you create or change an entry, it should give you an answer with the properties of the used entry.