Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3177

How to apply a filter to the oDataModel read function?

$
0
0

Hi UI5 gurus,

 

Been trying to follow Maksim Rashchynski - SCN Member of the Month April 2015's advice here: https://scn.sap.com/thread/3735171

 

But I'm not having much luck...

 

The Problem

I can't seem to get sap.ui.model.Filter working with ODataModel read function!

 

var la_filters = new Array(); // Don't normally do this but just for the example.
var ld_date = new Date("2015-08-20"); // Javascript Date object
var lo_pickedDateFilter = new sap.ui.model.Filter({                     path: "FilterEndDate",                     operator: sap.ui.model.FilterOperator.EQ,                     value1: ld_date              });
la_filters.push(lv_pickedDateFilter);
model.read("/TimeAccountCollection", null, la_filters);
// also tried the following but no luck... 
model.read("/TimeAccountCollection", null, null, true, la_filters);

So what happens is that its seems like the read function accepts the array of Filter(s) as a urlParamter which is what I suspect I'm doing wrong.

 

Google Chrome Dev Tools shows that the request looks like this:

http://<host>:<port>/sap/opu/odata/sap/MY_CUSTOM_SERVICE/TimeAccountCollection?[object%20Object]

Which is not giving me my desired results...

 

 

A Solution - urlParameters

var valid_date = "2015-08-20T00:00:00" // hardcoded for example
var arrParams = ["$filter=FilterEndDate eq datetime'" + valid_date + "'"];
// Fire off a new GET request to update the model based on the date.
model.read("/TimeAccountCollection", null, arrParams);

Google Chrome Dev Tools shows that the request looks like this:

http://<host>:<port>/sap/opu/odata/sap/MY_CUSTOM_SERVICE/TimeAccountCollection?$filter=FilterEndDate%20eq%20datetime%272015-08-20T00:00:00%27

This solution works for now...


If it helps I'm on UI5 version 1.26.1 but this shouldn't be an issue.

 

What am I doing wrong in my sap.ui.model.Filter example for the ODataModel read function?

 

If anyone has any ideas I'd love to hear from you.  I'm sure I'm missing something small.

 

Thanks.

 

Regards,

Ben


Viewing all articles
Browse latest Browse all 3177

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>