Skip to Content
0

How to use odata.create() returned response

Dec 09, 2016 at 07:04 PM

637

avatar image

Hello all,

I am working on an SAPUI5 project and have gotten a little stuck. I have successfully built a simple form which sends the input data using oData.create()to the backend odata service. I have run this in debug mode and can tell that the post action is working correctly. What I would like the app to do now is access a message generated in the create_entity method and included in the er_entity structure. It is important to note that the message is more than just a success or failure message. If the post is successful the message includes a newly generated document number. If it fails it will display one of many messages as to why it failed. When I created the oData service I included a parameter called message, so after everything runs on the backend I set er_entity-message to the message generated by the post. When I debug I can even watch as er_entity-message gets the message saved to it. I have read in SAP documentation that when I use the odata create operation the entity data should be returned in the body of the response. This sounds like er_entity should be accessible after I post my data to the back end. Pretty much I just want to be able to bind er_entity-message to a text field in my SAPUI5 project after the post is successful but I am unsure how to access the data from the response body. Your assistance achieving this is greatly appreciated.

Thanks,

Kristen

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

2 Answers

Best Answer
avatar image
Former Member Dec 09, 2016 at 09:06 PM
1

As per: https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.odata.v2.ODataModel.html#create

try something like this:

oModel.create("/EntitySet", data ,{
success: function(oData, response){
//oData -  contains the data of the newly created entry
//response - parameter contains information about the response of the request (this may be your message) }, error: function(oError){ //oError - contains additional error information. } });
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thank you so much for your solution! This was exactly what I was looking for. I had no luck finding an example that used the oData and response and explained what was actually going on so this was big help! I was able to get the message from oData and use it to set the text for a text element.

0
Noufal Farah Dec 13, 2016 at 12:06 PM
0

Hello,

I agree with Radeg answer, You have to use a basic call to understand what's going on. You can also check this :

oModel.create("/EntitySet", oEntry, {
       success : function(oData, oResponse) {
            // Success
            sap.m.MessageToast.show(" Created Successfully" );
       }
       error : function(oError) {
            // Error
          sap.m.MessageToast.show(" Creation failed" );
       }
  });
Share
10 |10000 characters needed characters left characters exceeded