Odata

POST operation in sapui5

How to perform a post operation in Odata service from sapui5 mobile application is explained here.x-csrf token handling will be done by the SAPUI5 OData model api.we dont have to worry about that.

Pre-requisites

1.odata service
2.sapui5 library files loaded

 Steps
  1. Instantiate OData model
  2.  
      var oModel = new sap.ui.model.odata.v2.ODataModel(
          "http://<host>:<port>/sap/opu/odata/sap/ZTEST_ODATA_SRV_01",
          true, "", ""
      );
    
  3. Create new entry which is to be posted to the service.
  4.   var oEntry = {};
      oEntry.Carrid = "AFO";
      oEntry.Carrname = "Airforce One";
      oEntry.Currcode = "USD";
      oEntry.Url = "www.techippo.com";
    
  5. Call create method of OData model passing the newly created entry
  6.   oModel.create("/FlightSet", oEntry, {
          method: "POST",
          success: function(data) {
              alert(JSON.stringify(data));
          },
          error: function() {
    
          }
      });
    



If you enjoyed this post, Please Share!!

0 comments :

Post a Comment

Powered by Blogger.