cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 - OData is not defined

rubens12
Participant
0 Kudos

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" : ""
				}
			);
		}

Accepted Solutions (0)

Answers (2)

Answers (2)

Sharathmg
Active Contributor

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

rubens12
Participant
0 Kudos

Hi Sharath, I download the lib datajs-1.0.1.min.js and call it in my index.html and now I am not geting any error, Does it correct?

Sharathmg
Active Contributor
0 Kudos

Possible. I would still recommend defining a variable to refer to the oData model and then invoke the services.

If now the error is fixed, you can continue your code.

Regards,

Sharath

0 Kudos

Hi Rubens,

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

Regards,
Rajat