Currently diving into the world of SAPUI5 and OData, I am in the process of creating a basic application that showcases employee data in a table. The objective is to add a new employee to the table whose information will be stored in the SAP backend.
While all GET requests are functioning as expected, encountering a server error (500) when attempting POST requests has left me puzzled. Could it be an issue with my create method or have I overlooked something crucial such as a specific header? (I understand that ideally odata.v2 should be used, but for the sake of this example... is there a glaring mistake that I'm missing?)
sap.ui.controller("zemployee_crud.EmpTable", {
onInit: function() {
var oView = this.getView();
var oTable = this.byId("employeeTable");
var oTemplate = new sap.m.ColumnListItem({
cells: [new sap.m.Text({
text: "{Empid}"
}), new sap.m.Text({
text: "{Empname}"
}), new sap.m.Text({
text: "{Empadd}"
})]
});
var sServiceUrl = "proxy/http/<server>:<port>/sap/opu/odata/sap/ZEMPLOYEE_SRV";
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, false);
this.getView().setModel(oModel);
oTable.bindAggregation("items", {
path: "/EmployeeSet",
template: oTemplate
});
},
Save: function() {
var oId = this.getView().byId("Id").getValue();
var oName = this.getView().byId("Name").getValue();
var oAddress = this.getView().byId("Address").getValue();
var oDialog = this.getView().byId("Dialog");
var oEntry = {};
oEntry.Empid = oId;
oEntry.Empname = oName;
oEntry.Empadd = oAddress;
var oModel = this.getView().getModel();
oModel.create("/EmployeeSet", oEntry, null, function (response) {
alert("Success!");
// handle response
}, function (Error) {
alert("Fail!");
// handle response
});
}