cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

how to initiate multiple batch requests, any sample code ?

venkatesha_n
Product and Topic Expert
Product and Topic Expert
0 Likes
5,354

Hi,

I am making two calls of sap.ui.model.odata.read method one after the other with different entitiy sets.

Since UI5 has inbuilt capability to send both GET operations in a single batch request, i can see only one $batch request in console.

When i checked this $batch call under 'Network' tab in chrome console, i saw there are two GET commands one after the other under 'Request Payload' and this whole $batch request is taking 3 seconds.

Whereas each of these read calls spearately takes 1.5 seconds.

-->So, i think when i make two read calls one after the other, browser is actually calling them sequentially.

What i want to achieve is to make two $batch requests for odata.read calls, which are written one after the other.

Is it possible with some settings or any sample code ?

BR,
Venky.

Accepted Solutions (0)

Answers (5)

Answers (5)

Hello Venky,

Try using ODataModel.setUseBatch(false);

If you want to have 2 different requests then try disabling the request as above and see whether it serves your purpose.

venkatesha_n
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Dinesh,

I tried it, then it will be two separate calls, but not two separate batch calls.

And this also voids further batching.

BR,
Venky.

Former Member
0 Likes

You can assign a groupID to the particular enitytype, which you want to load later.
Then you can call 2 submitchanges, 2nd one in the success of the first.

Former Member
0 Likes

Check this link and scroll down to "Batch Processing"

venkatesha_n
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Radek,

Thanks for your help.

I am using oDataModel.v2 api:

I followed the same link and tried it--> not working(still single batch call for two subsequent oDataModel.read calls).

in this link https://sapui5.netweaver.ondemand.com/sdk/#docs/guide/6c47b2b39db9404582994070ec3d57a2.html There is one code line:

oModel.submitChanges({groupId:"myGroupId", success: mySuccessHandler, error: myErrorHandler});

There is a success call function in the above statement, i think i should give success call back function in the oDataModel.read call, not here right ?

BR,
Venky.

Former Member

In oModel.read the success callback will trigger each time for a successfully read entry even if it is batch processing. You can either use submitChanges then success will trigger once per processed batch or use oModel.read and attach event batchRequestCompleted which will trigger once per batch.

Former Member
0 Likes

Hi Venkatesha

I believe you can set the batch group ID there so that it belongs to the same group and requested together.

venkatesha_n
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Hans,

Thanks for your suggestion.

I am new to SAPUI5, do you have a sample code to know how to set group ID to the already existing Odatamodel ?

BR,
Venky.

Former Member

this is the example of setting a group ID. I believe without setting the groupId for the request, SAPUI5 will generate a unique ID for each request so they will never inside the same batch. Take a look at the oDataModel.v2 api will help you I guess

var sGroupId = ...; //you can put anything you want, I myself use a timestamp.
oDataModel.setChangeGroups({
     "/record": { groupId: sGroupId } 
});
oDataModel.setDeferredGroups([sGroupId]); //deferred the group 

oDataModel.update("/record",data,{groupId : sGroupId}); //make sure to put the group in the request.
oDataModel.submitChanges({groupId: sGroupId});

venkatesha_n
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Hans,

I am using oDataModel.v2 api:

capture.png --> is the screenshot from manifest.json

What am i doing is:

oDataModel = that.getOwnerComponent().getModel();
aFiltersOData = that._createODataFilters("Entity1");
oDataModel.read("/Entity1", {
filters: aFiltersOData,
success: that._oDataReadBaseSuccessHandler
});

I tried your suggestion like this:

oDataModel = that.getOwnerComponent().getModel();
aFiltersOData = that._createODataFilters("Entity1");
var sGroupId = "Group1";
oDataModel.setChangeGroups({ "/Entity1": { groupId: sGroupId } });
oDataModel.setDeferredGroups([sGroupId]); //deferred the group
oDataModel.update("/Entity1",{groupId : sGroupId}); //make sure to put the group in the request. oDataModel.submitChanges({groupId: sGroupId});
oDataModel.read("/Entity1", {
filters: aFiltersOData,
success: that._oDataReadBaseSuccessHandler
});

it did not work(still single batch call for two subsequent oDataModel.read calls)

in your code snippet, there is a one 'data', i left it blank, is this causing any problem ?

oDataModel.update("/record",data,{groupId : sGroupId});

BR,
Venky.

Former Member
0 Likes

my code snippet is an example of batch request for update. you need to specify the group id for your read as well, and you need to use the submitChanges the success will trigger once all the request in the batch are processed successfully or you can attach batchRequestCompleted on your read function.

former_member269316
Discoverer
0 Likes

Hi Hans,

Thanks for the solution i implemented the same with below code

var sGroupId = "myId";

oODataModel.setChangeGroups({ "/C_Proc": { groupId: sGroupId } });

oODataModel.setDeferredGroups([sGroupId]); //deferred the group

oODataModel.read("/C_Proc",{

filters: aFiltersOData,

groupId : sGroupId,

urlParameters: { $select: parameters" },

success: that._oDataRead });

oODataModel.submitChanges({groupId: sGroupId});

Now my batch calls are different. But now i am getting error in other calls

How can i make it false in future, I want my other calls to be executed as before??

Thanks,

Lavanya

Former Member
0 Likes

Use sap.ui.model.odata.v2.ODataModel instead. It takes care of batch calls itself.