Skip to Content
Aug 01, 2020 at 06:52 AM

SAP UI5 filters not working while calling Odata read method

694 Views Last edit Aug 01, 2020 at 08:48 AM 3 rev

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 + "' ";, {
				//filters: [date],
				success: function (success, oResponse) {
					//	debugger;
				error: function (err, oResponse) {
					//	debugger;

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 .


gw-client.jpg (182.4 kB)
gw-client.jpg (182.4 kB)