0

I created table with data using JSONModel

    var oModel = new sap.ui.model.json.JSONModel(query);
    oTablePrio = sap.ui.getCore().getControl("idTablePrio2");
    oTablePrio.setModel(oModel, "Prio2"); 

Everythink look and work good.

Now i have added new column(prio) where i will change value. After changing i would like to save every rows( in the SAP ztable ) after clicking buton save . I made something like this

var oModel = new sap.ui.model.odata.v2.ODataModel(gServiceUrl);
        oModel.setUseBatch(true);
        for (var i = 0; i < data.length; i++) {
            sEntry.Matnr = data[i].Matnr;
            sEntry.Bbynr = data[i].Bbynr;
            sEntry.Prio = data[i].Prio;

oModel.update("/WielosztSet('"+data[i].Bbynr+"')", sEntry, {
                  method: "PUT",  function(){
                alert('Data Updated Successfully');
                 location.reload(true);
                  },function(){
                        sap.m.MessageToast.show('Update failed',{duration:1000});

                  }});
}

Now only it sends data only with the last row. I wrote that i cannot update more than one row in this way and I need to make batch. I connot find how to create working batch for uploding data with sap.ui.model.odata.v2.ODataModel

Please give me some advice.

Andrew Naumovich
  • 1,441
  • 1
  • 12
  • 15
  • Why don't you work with OData model directly? You could bind your table to OData model and get all the updates for free just with the "submitChanges" call, and they will be batched automatically. – Andrew Naumovich Aug 22 '17 at 17:01
  • sounds, greate. Could you tell me how can I do it? – Krzysztof Śliwa Aug 22 '17 at 17:16
  • Instead of thouthand words: https://openui5.hana.ondemand.com/#/topic/6c47b2b39db9404582994070ec3d57a2.html#loio6c47b2b39db9404582994070ec3d57a2 – Andrew Naumovich Aug 22 '17 at 17:39
  • I created Model like this: ' var gServiceUrl = "proxy/http/app-xxx.com:8001/sap/opu/odata/sap/ZPMR_KONFLIKTY/?&sap-client=200"; var goModel = new sap.ui.model.odata.v2.ODataModel({ serviceUrl: gServiceUrl, });` And i tried to bind data to sap.m.table but nothing happens. ` oTablePrio2.bindItems("Prio2>/d/results/", new sap.m.ColumnListItem({ cells : [ new sap.m.Text({ text : "{Prio2>Bbynr}"}), ` What can be the reason? – Krzysztof Śliwa Aug 22 '17 at 20:24
  • Are you able to get data back via "read" method? – Andrew Naumovich Aug 23 '17 at 07:08
  • it is hard to say. There is no error, but still no data in table i made line like this goModel.read("/WielosztSet('000000000064')"); it works in SAP – Krzysztof Śliwa Aug 23 '17 at 08:14
  • What to you see in network tab? Is there valid response? You can attach "success" callback to the "read" call and see the result in arguments. "it works in SAP" - what does it mean? – Andrew Naumovich Aug 23 '17 at 08:45
  • i made code like this goModel.read("/WielosztSet('000000000064')", {success: function(oData, response) { len=oData.results.length; alert(len); },failed: function(oData, response) { alert("Failed to get InputHelpValues from service!"); } In network tab i have URL: /sap/opu/odata/sap/ZPMR_KONFLIKTY/?&sap-client=200 METHOD: HEAD CODE 200 and dont knwo why METHOD: POST CODE: 202 URL: /sap/opu/odata/sap/ZPMR_KONFLIKTY/$batch?&sap-client=200 btw. i really appreciate your help. – Krzysztof Śliwa Aug 23 '17 at 11:31
  • So the question is: do you see the response data in network tab ? – Andrew Naumovich Aug 23 '17 at 11:39
  • Hmmm it looks like it teruns something: http://prntscr.com/gc28i4 other tabs: http://prntscr.com/gc242d http://prntscr.com/gc268c – Krzysztof Śliwa Aug 23 '17 at 12:50
  • ok, looks that the data call is correct. You need to bind your table to the odatamodel (see the ui5 documentation) and then all the changes to the bound fields, should automatically be updated by the model and the only thing you should do is to call "submitChanges" – Andrew Naumovich Aug 23 '17 at 14:52
  • Thank you for your help. I will keep trying to bind oDatav2 to my table. – Krzysztof Śliwa Aug 25 '17 at 06:33
  • https://stackoverflow.com/questions/26582351/sapui5-batch-operations-how-to-do-it-right – dotchuZ May 03 '18 at 11:12

1 Answers1

0

Before the call of the oModel.update assign the UseBatch to true:

oModel.setUseBatch(true);

Make your for:

for (var i = 0; i < data.length; i++) {
            sEntry.Matnr = data[i].Matnr;
            sEntry.Bbynr = data[i].Bbynr;
            sEntry.Prio = data[i].Prio;

oModel.update("/WielosztSet('"+data[i].Bbynr+"')", sEntry, {
                  method: "PUT",  function(){
                alert('Data Updated Successfully');
                 location.reload(true);
                  },function(){
                        sap.m.MessageToast.show('Update failed',{duration:1000});

                  }});
}

At the end of for put the submitChanges.

oModel.submitChanges();
oModel.setUseBatch(false); // Make false if you reuse this oModel.

Regards.