Quantcast
Channel: SCN: Message List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 9165

Re: Steps to perform Create and Update operations using oData

$
0
0

>How do I set content-type in my application(incase I need to do that explicitly) and in which file?

You don't set the content type directly. Instead when you create the model set true for the second parameter in the constructor:


oController.oModel = new sap.ui.model.odata.ODataModel("/cd164/admin/solutions/services/user.xsodata/", true);


This tells UI5 to use JSON instead of ATOM/XML.  Then the content-type will automatically be set to application/json.

 

For instance to create a new record you need only call model.create.  Pass the new entity into this method formatted as JSON. Here is an example:

 

  var oModel = sap.ui.getCore().byId("idodataCRUD").getController().oModel;

                                        var oEntry = {};

                                        oEntry.PERS_NO = "0000000000";

                                        oEntry.FIRSTNAME = sap.ui.getCore().byId("fName").getValue();

                                        oEntry.LASTNAME = sap.ui.getCore().byId("lName").getValue();

                                        oEntry.E_MAIL = sap.ui.getCore().byId("email").getValue();

 

 

                                        oModel.create('/Users', oEntry, null, function() {

                                                  alert("Create successful");

                                        }, function() {

                                                  alert("Create failed");

                                        });


Viewing all articles
Browse latest Browse all 9165

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>