Reputation: 141
I'm trying to have a batch read call in following manner.
Batch should have:
("/EntitySet", "Get", Filter1),
("/EntitySet", "Get", Filter2),
("/EntitySet", "Get", Filter3)
How to do such a batch call. I refered to this blog, but not of much help. https://archive.sap.com/discussions/thread/3957490
thanks in advance
Upvotes: 0
Views: 4579
Reputation: 5206
Do you need to procedurally do these calls (via ODataModel#read)?
If you are using regular bindings and then just apply your filters on them, then they will be automatically grouped into a batch (as long as you have enabled the batch mode in the ODataModel's constructor with the useBatch
parameter -- by default it is enabled).
If you are indeed using ODataModel#read, normally they are also batched together if batch mode is enabled.
If it does not work for some reason, you can always specify the groupId
when using read, respectively batchGroupId
when doing binding, to force the requests to be triggered together. You can generate a (pseudo)unique value for this with e.g. jQuery.sap.uid. When you generate this groupId, you should tell the OData model to "defer" its execution by using setDeferredGroups
. When you are done with your requests, you can "submit" the group using submitChanges
.
var sGroup = jQuery.sap.uid(),
oModel = this.getModel();
oModel.setDeferredGroups([sGroup]);
oModel.read("/EntitySet", {groupId: sGroup, filters: ...});
oModel.read("/EntitySet", {groupId: sGroup, filters: ...});
oModel.read("/EntitySet", {groupId: sGroup, filters: ...});
oModel.submitChanges({groupId: sGroup});
Upvotes: 3