0
votes

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
    });
}
2
Surely the chrome console shows more than just "Error 500"? I don't see something that is clearly wrong, so the actual error would be interesting. Are you aware of the SAP transactions to check for backend errors?Marc
"The following problem occurred: HTTP request failed500,Server Error,Fehler beim Verarbeiten der Ressource - ... Save @ EmpTable.controller.js?eval:126" (which is exactly the line where the create method is called). I've also copied the request payload from the network tab and copied it to the SAP Gateway Client where I used it as an http request which worked perfectly fine. It's just not working whenever I try to add an employee in chrome.masterR0shi

2 Answers

0
votes

This is a common scenario in UI5 development. The SAP Gateway Server won't tell the frontend the exact error, since that could leak data you wouldn't want it to.

To find out what the exact problem is, you should go to the transaction /IWFND/ERROR_LOG in your backend. There the request should be visible and you can see what exactly caused this error.

0
votes

Finally found the error -- there was a problem with the BSP application that was created via Eclipse. After fixing this issue, the POST requests worked just fine.