1

I got a button where I want to post data to my SAP backend on press-method:

         oCellBtnOtherchart.addContent(new sap.ui.commons.Button({
             text : "Save",
             press : function() {

                var sServiceUrl = "/MyEntitSet('0001')";

                var oModel = sap.ui.getCore().getModel();
                console.log(oModel);

                 var oParameters = {
                        "email" : "a",
                        "lastname" : "b",
                        "firstname" : "c",
                   };

                oModel.create(sServiceUrl, oParameters);

             }
         }));

My questions are:

  • In which method would this request end in backend? I expect MyEntitySet_CREATE_ENTITY()
  • Why doesnt it work, the error message is: HTTP request failed 405, Method Not Allowed

But why is it 405, is my Service URL Wrong? How do I Post data correctly to the SAP Backend?

SAP Troubleshooting Guide says: 405 Method Not Allowed o The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response must include an Allow header containing a list of valid methods for the requested resource. --> This does not help me right now, anybody knows how to include an allow header?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
dotchuZ
  • 2,621
  • 11
  • 39
  • 65

2 Answers2

13

Because there are only few threads on this topic at SO, which in my opinion do not answer the questions I had, I'll share my findings how to pass data to the backend via oModels create method:

First Define a type of your result entity (check your oData-Model to know the attributes, e.g. Name and YourID):

var oEntry = {};
oEntry.YourID = "0001";
oEntry.Name = "Peter";

Then fetch your model:

var oModel = sap.ui.getCore().getModel();

Then execute the create operation thanks to: https://sapui5.netweaver.ondemand.com/docs/api/symbols/sap.ui.model.odata.ODataModel.html

jQuery.sap.require("sap.ui.commons.MessageBox");
oModel.create('/EntitySet', oEntry, null, function(){
    sap.ui.commons.MessageBox.show(
         sap.ui.commons.MessageBox.alert("Success!");
     );
    },function(){
      sap.ui.commons.MessageBox.alert("Error!");
});

Results in Backend in Method "ENTITYSET_CREATE_ENTITY"-Method, where you can retrieve YourID and Name:

DATA: ls_data TYPE ycl_class_mpc=>ts_entity.

CALL METHOD io_data_provider->read_entry_data
  IMPORTING
    es_data = ls_data.

WRITE ls_data-name.
WRITE ls_data-yourid.

This example applies to single calls, you can see the result in ABAP is a structure. If you need to pass multiple datasets to the backend you should search for batch processing at https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.model.odata.ODataModel.html

dotchuZ
  • 2,621
  • 11
  • 39
  • 65
0

If you are still looking for a good blog on how to make a batch post then have a look at this post http://scn.sap.com/community/developer-center/front-end/blog/2012/11/18/gateway-batch-calls-from-sapui5

brimstone
  • 3,370
  • 3
  • 28
  • 49
Santhosh_Reddy
  • 274
  • 4
  • 18