Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

OData Filter by Multi value 'in()' for Javascript not working

klaudry
Discoverer
0 Likes
1,188

Hi, I'm using OData client v2 for my VUEJS app and trying to filter like this

$format=json&$top=50&$filter=substringof('COFFE', searchKey) and (origin eq 'BRA' or origin eq 'COL')

according to this light OData documentation we can use in() like this

$filter=substringof('COFFE', searchKey) and origin in ('BRA', 'COL')

the first one with 'OR()' works, but the second with 'IN()' unfortunately is not working, any idea?

2 REPLIES 2
Read only

Yogananda
Product and Topic Expert
Product and Topic Expert
0 Likes
1,085

klaudry

According to this Stack Overflow post, the correct syntax for using the in() operator in OData is as follows:

$filter=substringof('COFFE', searchKey) and (origin eq 'BRA' or origin eq 'COL')
Copy

The syntax you mentioned is incorrect:

$filter=substringof('COFFE', searchKey) and origin in ('BRA', 'COL')
Copy

I hope this helps. Let me know if you have any other questions.

Read only

evanireland
Product and Topic Expert
Product and Topic Expert
1,085

Since your URL has "substringof" rather than "contains", I assume that the server is implementing OData V2.

The "in" operator is defined only since OData V4, e.g. http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#_Toc31360968

(Even then, a V4 server might or might not support it).

So for a V2 service using the "or" operator might be the only available choice.