Batch request

Batch request

Batch request

A batch request allows us grouping multiple operations in one single request.

batch mode has to be enabled for this. You can do this by enabling it via the function setUseBatch

this._oServiceModel.setUseBatch(true);

or in your manifest.json

	"": {
				"dataSource": "mainService",
				"preload": true,
				"settings": {
					"useBatch": true
				}
			}

So here’s a coding sample with an batchGroupId

      sampleBatchRequest: function () {
            //Get all GroupId's
            var aDeferredGroup = this._oServiceModel.getDeferredGroups();

            //Add a new Group Id
            aDeferredGroup.push("doSomething");
            this.oServiceModel.setDeferredGroups(aDeferredGroup);

            //Create Parameters
            var oParameters = {groupId: "doSomething"};

            //do Something
            this.oServiceModel.read("/XXSet(key='XX')", oParameters);
            this.oServiceModel.remove("/XXSet(key='XXX')", oParameters);
            this.oServiceModel.create("/XXSet", { key: "XY", value: "XY"} ,oParameters);

            //Submit the Changes based on the groupId(doSomething)
            this.oServiceModel.submitChanges({
                groupId: "doSomething",
                success: function (data) {
                    //If the set of HTTP request headers of a batch request are valid,
                    // the HTTP response status code is always 202 (Accepted).
                    // This is irrespective of whether some retrieve operations
                    // or changesets within this batch request fail or not.

                    //Array of Responses
                    console.log(data._batchResponses);
                },
                error: function (err) {
                    //Do Stuff ?!
                }
            });
        }

Comments

Popular posts from this blog

Classes in UI5

How to extend a JSONModel