SAPUI5 create multiple value(batch) using post

纵饮孤独 提交于 2019-12-11 05:46:56

问题


To post data in the SAP Back-end I use:

oModel.create("/Dummyset", oEntry); //so far it works fine

Now I have multiple lines in my oEntry and it doesn't work. I found the following solution

aBatchOperation.push(contactBatchOperation);        
oModel.addBatchChangeOperations(aBatchOperation);
oModel.submitBatch(fSuccess,fError,true);

But unfortunately it's not working with my OData version 2.0 . I always get an error as

"addBatchChangeOperations is not a function"

Then I tried to find out which function I can use with OData v2. I could find this.

batchChanges.push(oModel._createBatchRequest("/AttributesSet", "POST", wert.Atrributes[i].name));
oModel._submitBatchRequest(oModel.setProperty("/AttributesSet", batchChanges), true);

But it still does not work. How do I fix it ?


回答1:


I suppose you want to bundle several create requests into one batch, right?

For ODataModel create method, you can define additional groupId. See below.

mParameters.groupId? ID of a request group; requests belonging to the same group will be bundled in one batch request

Basically you can submit multiple create with the same groupId which you can define yourself.

First you have to set a certain deferredGroups for ODataModel

var aDeferredGroup = oModel.getDeferredGroups().push("batchCreate");
oModel.setDeferredGroups(aDeferredGroup);

Then you call multiple create.

var mParameters = {groupId:"batchCreate"};
oModel.create("/Dummyset", oEntry1, mParameters);
oModel.create("/Dummyset", oEntry2, mParameters);
oModel.create("/Dummyset", oEntry3, mParameters);

At last, you can call submitChanges with one single batch for multiple requests.

oModel.submitChanges(mParameters);


来源:https://stackoverflow.com/questions/42696398/sapui5-create-multiple-valuebatch-using-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!