Skip to Content
Author's profile photo Mohit Kanoria

Make batch calls with multiple changeset ids in SAP UI5

Hello,

There are use cases where you might need to send multiple create, edit and delete request in a single batch. By default UI5 send the multiple request in a single batch with same change sets ids. So if any record fails, all the records are rolled back if changeset is not handled in backend.

With this blog I will show you, how you can send multiple CRUD operation in a single batch with different changeset ids. With different changeset ids all the records will be independent of each other.

Create a master map with following parameter

var mParameter = {
				
				urlParameters: null,
				groupId:"randomgroupid",
				success: function(innerdata) {

//This success handler will only be called if batch support is enabled. 
//If multiple batch groups are submitted the handlers will be called for every batch group.
			
				},
				error: function(oError) {
				
				}
			};

 

Create a map for each entry with following parameters

	var singleentry = {
				groupId: "randomgroupid",
				urlParameters: null,
				success: function(innerdata) {
					
				//The success callback function for each record
					
				},
				error: function(oError) {

				//The error callback function for each record
			};

 

For my current use case am reading a complete record from a sap.ui.table and sending it as a POST

 

//data model contains the table data
//Assign unique changeset id to singleentry
for (var i = 0; i < data.BP.length; i++) {
				singleentry.properties= data.BP[i];

				singleentry.changeSetId="changeset "+i;
				this.getOwnerComponent().getModel().createEntry("/Entity", singleentry);
			}

 

Finally submit the changes

this.getOwnerComponent().getModel().submitChanges(mParameter);

 

For more details refer : https://sapui5.hana.ondemand.com/#/api/sap.ui.model.odata.v2.ODataModel/methods/createEntry

 

Thanks

Mohit Kanoria

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Ravish Ramakrishna Shetty
      Ravish Ramakrishna Shetty

      Well writtern

      Author's profile photo Mohit Kanoria
      Mohit Kanoria
      Blog Post Author

      Thanks Ravish

       

      Author's profile photo Lucas Nebot
      Lucas Nebot

      Great blog post! This was exactly what I was looking for.

      Author's profile photo Mohit Kanoria
      Mohit Kanoria
      Blog Post Author

      Thanks, Lucas

      Author's profile photo Sai Battula
      Sai Battula

      Hi Mohit,

       

      I get below error when follow the above methodology

      Tried to use createEntry without created-callback, before metadata is available! -

      where do you colect response, in singlentry success?

       

      Thanks,
      Sai.