Skip to Content
0
Jan 31, 2018 at 06:21 PM

Save Multiple Row data to BackEnd

361 Views

Hi,

I'm having issues with saving multiple rows to the back-end. I don't know how to send all the rows in batch, so I was trying to send each row at a time but it hits <oModel.create("/MRU_ESTSet", oEntry> after it has put the last row into the oEntry.

submitButtonPress: function() {
	var oModel = this.getModel();
	var hasChanges = oModel.hasPendingChanges();

	if (hasChanges) {
		var mcJson = {};
                //get only rows with changes
		var modelChanges = oModel.getPendingChanges();
		mcJson = modelChanges;

		var mcJsonLength = Object.keys(mcJson).length;
		var mcJsonKey = Object.keys(mcJson);
		var officeCode = this.byId("officeCombo").getValue();
		var oEntry = {};

       //for each row get data
	for (var i = 0; i < mcJsonLength; i++) {
		var item = mcJsonKey[i];
		var obj = modelChanges[item];
		var estDate = this.convertDate(obj.ESTIMATE_DATE);

                oEntry.MRU_ID = obj.EST_MRU_ID.toString();
		oEntry.ESTIMATE_PRCT = obj.ESTIMATE_PRCT;
		oEntry.INSTALL_READ = obj.INSTALL_READ;
		oEntry.PLAN_ESTIMATE = obj.EST_INSTALL;
		oEntry.MRU_DATE = estDate;
		oEntry.OFFICE_CODE = officeCode.toString();*/


oModel.create("/MRU_ESTSet", oEntry, {
        success: function(oData, response) {
	       sap.m.MessageBox.alert("MRU: " + oEntry.MRU_ID + " EST DATE:                " + oEntry.MRU_DATE + " SAVED!");},
	error: function(oError) {
		sap.m.MessageBox.alert("Error Saving Entries!!");
	}
	});

	}
	} else {
	sap.m.MessageBox.alert("No Changes To Submit");
	}

}