Skip to Content
0

SAPUI5 - OData is not defined

May 04, 2017 at 12:04 PM

119

avatar image

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" : ""
				}
			);
		}
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Sharath M G May 04, 2017 at 12:23 PM
1

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded

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?

0

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