SAPUI5 - batch operations - how to do it right?

I got several EntititySets that I want to update in my SAP backend, so I fetch my data (payload) as JSON and put it in the request (its successful in node "data"):

code:

var oTreeJSON = oTreeTable.getModel().getProperty("/root");
var oModel = sap.ui.getCore().getModel();
var batchChanges = [];  

for (var i = 0; i < oTreeAll.length; i++) {
    batchChanges.push(oModel.createBatchOperation("/sap/opu/odata/sap/MY_SERVICE/?$batch", "POST", oTreeAll[i]));
}

oModel.submitBatch();

      

My request looks like this:

enter image description here

Where should it arrive at SAP (which method)? What am I doing wrong, there is no error anywhere, but no call came through in my backend ... Glad about every hint! Thank.

Working example with reduced complexity:

var oEntry = {};
oEntry.MyId = "00000001";
oEntry.Value = "300";

batchChanges.push(oModel.createBatchOperation("MyEntitySet", "POST", oEntry, null));
oModel.addBatchChangeOperations(batchChanges); 
oModel.setUseBatch(true);
oModel.submitBatch();

      

For the record, method calls:

  • 1) / IWBEP / IF_MGW_CORE_SRV_RUNTIME ~ CHANGESET_BEGIN: SAP EXIT clause.
  • 2) / iwbep / if_mgw_appl_srv_runtime ~ create_entity. (n-times) // make your stuff with entity
  • 3) / iwbep / if_mgw_core_srv_runtime ~ changeset_end: SAP clause COMMIT RUN.
+3


source to share


2 answers


oModel.addBatchChangeOperations(batchChanges);
oModel.setUseBatch(true);

      



If you need to set a breakpoint in the backend for batch operations, just set a breakpoint in the CHANGESET_BEGIN

or method CHANGESET_END

.

+4


source


Submit my POST code for sap.ui.model.odata.v2.ODataModel

"models": { "": { "dataSource": "mainService", "preload": true, "settings" : { "useBatch" : true, "defaultBindingMode": "TwoWay", "defaultCountMode" : "None", //default is sap.ui.model.odata.UpdateMethod.Merge "defaultUpdateMethod" : "Put" } } }



var sPath = oView.getBindingContext().getPath();
oModel.setDeferredGroups(["editGroup"]);
oModel.update(sPath, oData, {groupId: "editGroup"});
oModel.update(sPath, oData2, {groupId: "editGroup"});
oModel.submitChanges({
    groupId: "editGroup",
    success: this.successCallback, 
    error: this.errorCallback
});

      

Actually v2.ODataModel will use Batch by default, use update()

/ create()

/ delete()

without setDeferredGroups()

and submitChanges()

ok. But in this case I get a callback for every request I use submitChanges

to combine the responses into one.

+1


source







All Articles