cancel
Showing results for 
Search instead for 
Did you mean: 

SAP UI5 filters not working while calling Odata read method

ronak_pandya
Explorer
0 Kudos

Hello Experts,

I am fairly new to the world of SAP UI5, I am trying to pass Date parameters from UI5 to Odata URL but it is giving me bad request . I want to create below URL for Odata service

/ZGW_OMNI_TRACK_SRV/etResultSet?$filter=SoDate ge datetime'2020-07-16T00:00:00' and SoDate le datetime'2020-07-23T00:00:00' .

Above URL is working fine in gateway client

To achieve this I have written below code

	var date = this.byId("idFromDate").getValue();
			var date2 = this.byId("idToDate").getValue();
			var oDateFormat = sap.ui.core.format.DateFormat.getInstance({
				pattern: "yyyy-MM-ddTHH:mm:ss"
			});
			var oDate = oDateFormat.format(oDateFormat.parse(date));
			var oDate2 = oDateFormat.format(oDateFormat.parse(date2));


			// var fromDate = this.getView().byId('idFromDate').getValue();
			// var toDate = this.getView().byId('idToDate').getValue();


			var date = new Filter({
				path: "SoDate",
				operator: FilterOperator.BT,
				value1: oDate,
				value2: oDate2
			});


			//Build Odata Service		
			var sServiceUrl = "/sap/opu/odata/sap/ZGW_OMNI_TRACK_SRV";


			//var url = sServiceUrl.concat(date);
			var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceUrl, false);
	


			var sUrl = "/etResultSet?$filter=SoDate ge datetime'" + oDate + "' and SoDate le datetime'" + oDate2 + "' ";
			oModel.read(sUrl, {
				//filters: [date],
				success: function (success, oResponse) {
					//	debugger;
					alert("READ SUCCCESSFULLY");
				},
				error: function (err, oResponse) {
					//	debugger;
					alert(err.statusText);
				}
			});

I even tried passing filter in read method, but still I am not able to achieve this, please let me know what I am missing .

Accepted Solutions (0)

Answers (0)