cancel
Showing results for 
Search instead for 
Did you mean: 

How to perform Create and Update operations together in V2 OData Model?

0 Kudos

Hello Experts,

I have a scenario where I have to perform create (Deep entity) and update operation together in a single batch call using v2 OData Model.

I have tested individual operation at a time, and its working fine. But when I try to perform both update and create together in a single batch call, it only performs update and gives timeout error for create. I have tried various combinations of "groupId" and "changeSetId", but it did not work.

Note: Is it possible to perform both create and update together in a single batch call in V2 OData model as it works in V1 model ??

Regards,

Archana

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member322772
Active Participant

You should be able to send them both in the same batch request. Set a single deferred group against oModel, and when you call create() and update(), give them both the same groupID. Then when you call submitChanges with the ID it should send them both in the same batch request.

former_member322772
Active Participant
0 Kudos

What happens when you set back-end breakpoints for each request type? Does the create request reach at all?

0 Kudos

Yes, when I set back-end breakpoints for each request type, both (update and create request) reaches in the back-end.

The problem is, When I mention groupId and deferred groups for both, it tries to run both the requests together and gives Socket connection time out error. So none of the requests get executed.

So I have to mention groupId and deferred groups for both the requests. But by doing so, it shows 2 separate $batch calls in the network tab of chrome developer tool, which is wrong as it should be in the same batch call with single $batch entry.

Below is the code I am trying:

oModel.create("/EntitySet1", request, { groupId: "batchUpdateGroup1" }); ----> request containing header and child fields (deep entity structure)

oModel.update("/EntitySet2(DoId=guid\'" + request.Id + "\',Isflag='X')", request, { groupId: "batchUpdateGroup2"});

oModel.setUseBatch(true);

oModel.setDefaultBindingMode("TwoWay");

oModel.setDeferredGroups(["batchUpdateGroup1"]);

var aDeferredGroups = oModel.getDeferredGroups();

aDeferredGroups=aDeferredGroups.concat(["batchUpdateGroup2"]);

oModel.setDeferredGroups(aDeferredGroups);

oModel.submitChanges({ aDeferredGroups, success: function(oData, oResponse) { }, error: function(oError) { } });

Here, I can see 2 batch calls.. Is it an expected behavior?Is it possible to make both calls in a single $batch?

Regards,

Archana