7

What is the correct way to filter w.r.t. multiple fields when applying $filter command on more than one field/value pair from JavaScript?

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
Bvrce
  • 2,170
  • 2
  • 27
  • 45

2 Answers2

8

It's very canonical.

http://192.168.75.8:5555/Konrad01/
  xrmservices/2011/OrganizationData.svc/
  LeadSet%28%29?$filter=
    Field1%20eq%20%27Value1%27%20and%20Field2%20eq%20%27Value2%27

EDIT:

More readable version.

http://Server:Port/Organization/XrmServices/2011/OrganizationData.svc/
  LeadSet()?$filter=Field1 eq 'Value1' and Field2 eq 'Value2'
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
  • 1
    I took the liberty of correcting %-syntax to more readable one. –  Mar 07 '13 at 19:01
  • 1
    I remember there being problems reported if using white spaces instead of %20, the URL cannot contain white spaces. The edit would be very useful for those who do not know that %20 is white space, but does the query work with white spaces? – Bvrce Mar 08 '13 at 07:46
  • That's **exactly** why I pasted in the %-fied URL - I anticipate and pre-resolve the problems! (True meaning: I was lazy and simply copied what's on the URL in the browser. Now that I look at it, it's cryptically ugly **even** for someone who knows about the %-syntax.) I just rechecked the canonical version and it worked too, so there's a converter in the browser kicking in. Also, that beg the off-topic question as to when the spaces are converted. Is it at the server or in the browser? I think it's the server because I recall executing the canonical string from the source code and it worked. – Konrad Viltersten Mar 08 '13 at 11:33
  • I am of the opinion that it is at the browser; URL's cannot contain white spaces. What is w.r.t? The edit removed my explicit reference to OData, but it is implied I guess. – Bvrce Mar 08 '13 at 13:16
  • I see OData is in the title, so that is OK. – Bvrce Mar 08 '13 at 13:16
  • @Bvrce Oops, sorry. My math background shining through... W.r.t. is abbreviation of *with respect to*, an expression mostly used when deriving or integrating in multi dimensional spaces. Still applicable in this formulation but if you find it unclear, it probably is so go ahead and change it. I've been known to be 3 x 100%. (100% correct, 100% polite and 100% incomprehensible) – Konrad Viltersten Mar 08 '13 at 17:44
  • @Bvrce BTW, I love the new image. Cool four-legger. – Konrad Viltersten Mar 08 '13 at 17:46
4

Put an and in between

Example:

http://YourServer.com/YourOrg/xrmservices/2011/OrganizationData.svc/ContactSet()?$filter=FirstName eq 'George' and LastName eq 'Washington'

Daryl
  • 18,592
  • 9
  • 78
  • 145
  • whats wrong with the following statement `http://YourServer.com/YourOrg/xrmservices/2011/OrganizationData.svc/OpportunityProductSet()?$filter=New_opportunityproductmapid eq '16817F20-3C27-E111-9DD8-005056A023F0' AND New_SequenceNumber eq '1'` – Chirag Aug 04 '14 at 13:10
  • @Chirag, don't post a question in a comment. Ask a new question. But to answer yours, 99% of the time, capitalization (and, not AND) – Daryl Aug 04 '14 at 22:40
  • posting question is disabled from my account. by the way thanks for answer, but now i am getting another error that `Operator 'eq' incompatible with operand types 'System.Nullable'1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' and 'System.String' at position 93.` please help me. – Chirag Aug 05 '14 at 07:13
  • @Chirag the error is self explanatory. (Try 1 not '1') – Daryl Aug 06 '14 at 15:21
  • Thanks @Daryl. I have got the solution myself before ur answer. but thanks for great help of "and" not "AND", +1 for that. – Chirag Aug 07 '14 at 11:08