on 04-04-2023 8:27 PM
Hi All
I have a Table Control in View having multiple editable rows of data. We want to submit all rows data to backend system using Batch of all rows but on save button backend system getting duplicated data of last row in all records , lets say if table is having 8 rows, all 8 rows receiving data of 8th row (last record) only. Which means batch is not working or some issue with loop in below mentioned code. Please check.
onSave: function(oEvent) {
this._oViewModel.setProperty("/enableCreate", false);
var requestBody = {};
var that = this, oView = this.getView(),
oModel = this.getModel();
//spath = oView.getBindingContext().getPath();
//oModel = sap.ui.getCore().getModel("Leaves"),
//var bindingContext = this.getView().getBindingContext();
// var object = bindingContext.getObject();
var oTable = this.getView().byId("table_id");
var leave = sap.ui.getCore().getModel("Leaves");
var len = oTable.getItems().length; // Get total Line Items in table
oModel.setUseBatch(true);
oModel.setDeferredGroups(["foo"]);
var mParameters = {
groupId:"foo",
success:function(odata, resp){
console.log(resp); },
error: function(odata, resp)
{ console.log(resp); }
};
/********** Updating Odata MOdel ******************/
for (var i = 0; i < len; i++) {
var oEntry = leave.oData.results[i];
requestBody.Comments = this.getView().byId("com_id").getValue();
requestBody.Pernr = leave.oData.results[i].Pernr;
requestBody.Pernr = leave.oData.results[i].Pernr;
requestBody.Atext = leave.oData.results[i].Atext;
requestBody.Begda = leave.oData.results[i].Begda;
requestBody.Endda = leave.oData.results[i].Endda;
requestBody.Ktalg = leave.oData.results[i].Ktalg;
requestBody.Subty = leave.oData.results[i].Subty;
oModel.create("/LeaveRequestSet", requestBody, mParameters, {
method: "POST",
success: function(data) {
},
error: function(e) {
} }); }
/********** Updating Odata MOdel ******************/
// abort if the model has not been changed
if (!oModel.hasPendingChanges("foo")) {
MessageBox.information(
this._oResourceBundle.getText("Foo"), {
id: "noChangesInfoMessageBox",
styleClass: that.getOwnerComponent().getContentDensityClass()
}
);
return;
}
this.getModel("appView").setProperty("/busy", true);
if (this._oViewModel.getProperty("/mode") === "edit") {
// attach to the request completed event of the batch
oModel.attachEventOnce("batchRequestCompleted", function(oEvent) {
if (that._checkIfBatchRequestSucceeded(oEvent)) {
that._fnUpdateSuccess();
} else {
that._fnEntityCreationFailed();
MessageBox.error(that._oResourceBundle.getText("updateError"));
}
});
}
oModel.submitChanges(mParameters);
},
<br>
Issue have been resolved. Issue was array within loop . Following code is working.
for (var i = 0; i < len; i++) {
var oEntry = leave.oData.results[i];
//requestBody.RequestId = object.RequestId;
//requestBody.Gjahr = object.Gjahr;
var requestBody1 = {
Comments : this.getView().byId("com_id").getValue(),
Pernr : leave.oData.results[i].Pernr,
Atext : leave.oData.results[i].Atext,
Begda : leave.oData.results[i].Begda,
Endda : leave.oData.results[i].Endda,
Ktalg : leave.oData.results[i].Ktalg,
Subty : leave.oData.results[i].Subty
};
oModel.create("/LeaveRequestSet", requestBody1, mParameters, {
method: "POST",
success: function(data) {
},
error: function(e) {
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
10 | |
10 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.