Search code examples
sapui5abapsap-gateway

SAPUI5 oData POST 500 error


I'm trying to do a oData create on checkbox pressed and getting the following errors. Not sure if this is front end or a back end ABAP issue as have got this same function working in another project.

It is failing on the create part but strangely is still passing through the details for SiteId, ArticleNumber, VarianceDate & Confirmed.

console log error

gui error log

// Set CheckBox status, X for true, blank for false
    onVarianceChecked: function (oEvent) {
        var oEntry = {};

        var bindingContext = oEvent.getSource().getBindingContext(this.MODEL_VIEW);
        var path = bindingContext.getPath();
        var object = bindingContext.getModel("SI").getProperty(path);

        // Pass in the Header fields
        oEntry.SiteId = this.SiteId;
        oEntry.ArticleNumber = object.ArticleNumber;
        oEntry.VarianceDate = moment(new Date(object.VarianceDate)).format('YYYY-MM-DDTHH:mm:ss');

        // Set X or blank
        if (oEvent.getParameter("selected") === true) {
            oEntry.Confirmed = "X";
        } else {
            oEntry.Confirmed = "";
        }

        // Do the create
        var oModel = this.getView().getModel("SI");
        oModel.create("/VarianceHeaderSet", oEntry, {
            success: function () {
                console.log("Variance confirmed");
                MessageToast.show("Variance confirmed", {
                    duration: 1000
                });
            },
            error: function (oError) {
                console.log("Error, variance could not be confirmed");
                MessageToast.show("Error, variance could not be confirmed", {
                    duration: 1000
                });
            }
        });
    }

Solution

  • '000000000' is the initial value for Edm.DateTime, hence it will fail when you have modelled a DateTime property to not be nullable.

    Go to SEGW and change the property to "nullable" or make sure that you always provide a correct Date in the POST.