Krzysztof Śliwa
Krzysztof Śliwa

Reputation: 1

sapui5 batch with sap.ui.model.odata.v2.ODataModel

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.

Upvotes: 0

Views: 3729

Answers (1)

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.

Upvotes: 0

Related Questions