Skip to Content
avatar image
Former Member

Save multiple records from SAPUI5 to DB Table through ODATA service

Hi Everyone,

I want to save multiple records from UI to DB tables through Odata service.

So I created a post request for saving data and sent multiple records one by one. But it's saving only one record. and if I comment code line no. 4 then it's show an error message that default changeset can handle only one operation.

Code is shown below:

var onewModel = this.getView().getModel("new");

var aBookings = onewModel.getProperty("/Bookings");

var oDataModelForData = this.getView().getModel();

oDataModelForData.setUseBatch(false);

var oNeedfulData = {};

var oTable = this.getView().byId("tablegrid");

var aItems = oTable.getItems();

for( var w = 0; w <aItems.length ; w++) {

oNeedfulData.AirlineCode = aBookings[w].AirlineCode;

oNeedfulData.ConnectionNumber = aBookings[w].ConnectionNumber;

oNeedfulData.CityFrom = aBookings[w].CityFrom;

oNeedfulData.CityTo = aBookings[w].CityTo;

oDataModelForData.create('/FLBOOKINGSet', oNeedfulData);

}

Thanks in advance

Regards

Sukhram Bhamboo

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    May 30, 2017 at 07:56 AM

    Try this:

    oDataModelForData.create('/FLBOOKINGSet', oNeedfulData,{changeSetId: w});

    It will send each entry in a separate change set and the changeset id will be your loop's iterator variable 'w'.

    And if you want to process all records in one changeset you need to implement changeset_begind and changeset_process methods in the Gateway. You can check class /IWBEP/CL_MGW_RT_SFLIGHT for an example.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Javascript can be tricky for people coming from e.g. ABAP background as it behaves in a different way. Google javascript "closures" it will explain the problem you were having.

  • Jun 09, 2017 at 04:46 AM

    you can try using batch operation

    var batchArray = [];
    
    if (!this.oModel) {
    	this.oModel = new ODataModel("/sap/opu/odata/sap/BPMON_SELOPS_SRV/", {
    		defaultBindingMode: "TwoWay",
    		refreshAfterChange: false
    	});
    }
    
    for (var h = 0; h < renamed.length; h++) {
             batchArray.push(this.oModel.createBatchOperation("entityset(data1, data2, data3)", "PUT"/"POST"/"DELETE", oEntry));
    }
    
    this.oModel.addBatchChangeOperations(batchArray);
    this.oModel.setUseBatch(true);
    this.oModel.submitBatch(jQuery.proxy(this.successcallback, this), jQuery.proxy(this.failurecallback, this), true);
    
    
    In the NetWeaver Gateway, you need to redefine the changesetbegin and changesetend methods
    
    
    
    
    
    Add comment
    10|10000 characters needed characters exceeded