0

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
    });
}
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
susosaurus
  • 459
  • 10
  • 28
  • 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 May 05 '20 at 12:26
  • "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. – susosaurus May 05 '20 at 12:33

2 Answers2

0

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.

Jan W
  • 904
  • 2
  • 7
  • 14
  • But I can only see the requests in /IWFND/ERROR_LOG when I try to post a request via the SAP Gateway Client right? – susosaurus May 05 '20 at 13:36
  • Because copying the request payload into the Gateway Client works fine and no error is thrown. I only get the error when I try to do it in Chrome. – susosaurus May 05 '20 at 13:38
  • No. `/IWFND/ERROR_LOG` logs all OData related errors, no matter how the service is accessed (UI5, GW Client, Postman, iOS App, etc). – Marc May 05 '20 at 13:43
  • Other helpful transactions: `ST22` and `/IWBEP/ERROR_LOG` (on the system where the OData service is implemented aka backend server). `/IWFND/ERROR_LOG` and `/IWFND/TRACES` (on the system where the OData service is registered aka gateway). Gateway and backend server may be the same in an embedded deployment scenario. – Marc May 05 '20 at 13:49
  • Ok, thanks. I've checked both /IWBEP/ERROR_LOG and /IWFND/ERROR_LOG, however, there are no errors reported after I get the error in Chrome. I also tried a trace via /IWFND/TRACES - interestingly, the POST request via Chrome displays 'txt' for the response format while the POST request via SAP Gateway Client has 'xml'. Could this be the origin of my error? – susosaurus May 05 '20 at 14:00
0

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.

susosaurus
  • 459
  • 10
  • 28