5

I got multiple EntititySets which I want to update in my SAP Backend, therefore I fetch my data (payload) as JSON and put it in a request (its successfully in the 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 in SAP (which method)? What am I doing wrong, there is no error anywhere, but no call arrived in my backend... Glad about every hint! Thanks.

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 Proposal EXIT.
  • 2) /iwbep/if_mgw_appl_srv_runtime~create_entity. (n-times) // do your stuff with the entity
  • 3) /iwbep/if_mgw_core_srv_runtime~changeset_end: SAP Proposal COMMIT WORK.
dotchuZ
  • 2,621
  • 11
  • 39
  • 65

2 Answers2

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

In case you need set a breakpoint in backend for batch operations, just set a break point in method CHANGESET_BEGIN or CHANGESET_END.

Haojie
  • 5,665
  • 1
  • 15
  • 14
  • its not arriving in the backend ... do I have to set any header-data manually? (did not have to set any headers before, all in the same domain, thus I thought its the same this time)... which is the correct method? got breakpoints in /IWBEP/IF_MGW_CORE_SRV_RUNTIME~CHANGESET_BEGIN and in /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGIN, both dont get activated.. – dotchuZ Oct 27 '14 at 07:56
  • Hi, you need add the batch operations. oModel.addBatchChangeOperations(batchChanges); oModel.setUseBatch(true); – Haojie Oct 27 '14 at 08:12
  • I got it running for a version with reduced complexity, now I got to adapt it.. at least the call is being transfered to the backend. I will update my answer, I think your two hints are necessary, so I'll accept it as answer :-) – dotchuZ Oct 27 '14 at 09:25
  • `addBatchChangeOperations` is method in `sap.ui.model.odata.ODataModel`, how to do it in `sap.ui.model.odata.v2.ODataModel` ? – Tina Chen Sep 25 '17 at 08:01
1

Post 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 useBatch by default, use update()/create()/delete() without setDeferredGroups() and submitChanges() is OK. But in that way, I will get callback for each request, I use submitChanges to merge the responses to one.

Tina Chen
  • 2,010
  • 5
  • 41
  • 73