I'm currently trying to learn the basics of SAPUI5 and OData. I'm building a simple application where employee data is displayed in a table and you can add a new employee whose data will be written to the SAP backend.
All the GET requests work, the POST requests, however, always result in a server error (500). Is my create method somehow malformed or did i forget something (special header etc.)? (I know I should actually be using odata.v2 but just for this example's sake... is there something clearly wrong that I'm just not seeing?)
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
});
}