Skip to Content
0

how to initiate multiple batch requests, any sample code ?

Feb 22, 2017 at 11:24 AM

229

avatar image

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

Dinesh Bhandarkar
Feb 22, 2017 at 05:47 PM
0

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.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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.

0
avatar image
Former Member Feb 22, 2017 at 12:05 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Feb 22, 2017 at 12:20 PM
0

Hi Venkatesha

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

Show 5 Share
10 |10000 characters needed characters left characters exceeded

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.

0
Former Member
Venkatesha N

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});

1

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.

capture.png (8.9 kB)
0
Former Member
Venkatesha N

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.

0
Former Member

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

0
avatar image
Former Member Feb 23, 2017 at 09:03 AM
0

Check this link and scroll down to "Batch Processing"

Show 2 Share
10 |10000 characters needed characters left characters exceeded

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.

0
Former Member
Venkatesha N

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.

1
avatar image
Former Member Jan 09 at 09:06 AM
0

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.

Share
10 |10000 characters needed characters left characters exceeded