Skip to Content

SAPUI5 - OData is not defined

I am trying send some data to sap gateway service. I am using this example the method "save", but when I try do it in my code I get an error "OData is not defined"

Below is the method when I try do it.

		handleConfirmationMessageBoxPress: function(oEvent) {
			var bCompact = !!this.getView().$().closest(".sapUiSizeCompact").length;
			MessageBox.confirm(
				"Deseja confirmar a transferência?", {
					icon: sap.m.MessageBox.Icon.SUCCESS,
					title: "Confirmar",
					actions: [sap.m.MessageBox.Action.OK, sap.m.MessageBox.Action.CANCEL],
					onClose: function(oAction) {
						if (oAction == "OK") {
							var oParameters = {};
							oParameters.loginfrom = this.getView().byId("multiInput").getValue();
							oParameters.loginfrom = this.getView().byId("loginPara").getValue();
							oParameters.loginfrom = this.getView().byId("datade").getValue();
							oParameters.loginfrom = this.getView().byId("datapara").getValue();
							
							OData.request({
		                        requestUri : "http://<host name>:<port no>/sap/opu/odata/sap/ZMM_EMP_SRV/EmployeeSet",
		                        method : "GET",
		                        headers : {
		                                                "X-Requested-With" : "XMLHttpRequest",
		                                                "Content-Type" : "application/atom+xml",
		                                                "DataServiceVersion" : "2.0",
		                                                "X-CSRF-Token" : "Fetch"
		                                                }
		                                    },
		                                    function(data, response) {
		                                                header_xcsrf_token = response.headers['x-csrf-token'];
		                                                var oHeaders = {
		                                                            "x-csrf-token" : header_xcsrf_token,
		                                                            'Accept' : 'application/json',
		                                    };
		                        OData.request({
		                                                requestUri : "http://<host name>:<port no>/sap/opu/odata/sap/ZMM_EMP_SRV/EmployeeSet",
		                                                method : "POST",
		                                                headers : oHeaders,
		                                                data:oParameters
		                                    },
		                                                function(data,request) {
		                                    			MessageToast.show("Transferência realizada!");       
		                                                location.reload(true);
		                                    },          function(err) {
		                                    			MessageToast.show("A transferência falhou!");
		                                    });
		                        }, function(err) {
		                                                var request = err.request;
		                                                var response = err.response;
		                                                alert("Error in Get — Request " + request + " Response " + response);
		                                    });  
							


						} else {
							MessageToast.show("Transferência não realizada");
						}


					}.bind(this),
					styleClass: bCompact ? "sapUiSizeCompact" : ""
				}
			);
		}
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • May 04, 2017 at 12:23 PM

    OData.request - You have used a variable OData directly. There is not api reference or any understanding for the interpreter.

    Hence the error.

    You need to define an OData model using its consutructor and then invoke the methods request and response.

    Regards,
    Sharath

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 08 at 08:19 PM

    Hi Rubens,

    Did you solve this issue?
    I am also facing the same issue..

    Regards,
    Rajat

    Add comment
    10|10000 characters needed characters exceeded