Search code examples
odatasapui5

SAPUI5 OData V2 Batch Operations with multiple differed groups


I'm trying to do a batch operation with multiple groupids in a single batch request. and need to get results in two different batch responses.

But when I initiate the request only one group has been submitted and only get one batch response.

Here is my code

oModel = this.getOwnerComponent().getModel("mymodel");


                $.sap.itemArray.forEach(function (entry) {
                    if (p < $.sap.itemArray.length) {
                        var oData = {
                            "AUTO_ID": entry.Id,
                            "VALUE": entry.Value,

                        };
                        mParameters.groupId = "createGroup1";
                        oModel .create("/Table1", oData, mParameters);

                    }
                    p++;
                });


for (p = 0; p < $.sap.itemArray2.length; p++) {
                    var oData = {
                        "Item2ID" : $.sap.itemArray2[p].ItemsId,
                        "Value" : $.sap.itemArray2[p].Value

                    };

                    mParameters.groupId = "createGroup2";

                    oModel .create("/Table2", oData, mParameters);
                    }


    oModel.setDeferredGroups(["createGroup1","createGroup2"]);
                oStyleSizeModel.submitChanges({
                    success: function(recievedObject){
                          var responses = recievedObject.__batchResponses;
                      },
                    error: function (oError) {
                        var oBody = oError.responseText;

                    }
                });

Here is the response I got.

enter image description here

And here it only execute the first group's requests and only returned one batch response.

How to execute multiple batch requests with different group Ids and get each group's responses.


Solution

  • I believe you want to group each change separately. You need to use the concept of Change Set (not Group).

    1. Use createEntry method instead of create.
    2. For each call, use different changeSetId, but same groupId.
    3. Call submitChanges passing the groupId.