SAPUI5 oModel.create() - how to post data to the SAP backend?

前端 未结 2 1511
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-01 08:08

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

         oCellBtnOtherchart.addContent(new sap.ui.commons.Button({
             t         


        
相关标签:
2条回答
  • 2021-01-01 08:12

    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

    0 讨论(0)
  • 2021-01-01 08:24

    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

    0 讨论(0)
提交回复
热议问题