Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

weird but i can't figure this out or find a solution anywhere....

I want to filter on two values on a GET in REST URL from javascript. So since this is from ECMA I am just using filtering in the url...

something like:

/_vti_bin/ListData.svc/Table?$filter=Color eq 'Red'&Active eq false

doesn't work so I have tried:

/_vti_bin/ListData.svc/Table?$filter=((Color eq 'Red') and (Active eq false)
/_vti_bin/ListData.svc/Table?$filter=Color eq 'Red' and Active eq false
etc

i know that you can only use one operator at a time in a URL but I not sure how to set two or three field filters in one URL like this

appreciate any help.

share|improve this question
    
Just an FYI as I know this does not pertain directly to your question, you can not filter on multi-selectable choice fields. sharepoint.stackexchange.com/questions/14482/… –  Robert Kaucher Jun 26 '13 at 19:02
    
Thanks rob...good to know! –  Justin Jun 28 '13 at 10:34

2 Answers 2

up vote 4 down vote accepted

Everywhere in this answer replace sp2010 with your site url, Table with your list name, PortalHomeDataContext with your site name (without spaces) + DataContext and RestTest.ServiceReference1 with your generated namespace.

This is tested against a SharePoint 2010 site:

http://sp2010/_vti_bin/listdata.svc/Table?$filter=(Color eq 'Red') and (Active eq false)

A very efficient way of getting the syntax (provided you know C# and LINQ) is the following:

  1. Create a Console Application using visual studio
  2. Add a service reference to http://sp2010/_vti_bin/listdata.svc
  3. Change to console application to something like this:

    using System;
    using System.Linq;
    using RestTest.ServiceReference1;
    
    namespace RestTest
    {
      class Program
      {
        static void Main(string[] args)
        {
          var context = new PortalHomeDataContext(new Uri("http://sp2010/_vti_bin/listdata.svc"));
          context.Credentials = System.Net.CredentialCache.DefaultCredentials;
          var data = from d in context.Table
                     where d.Color == "Red" && d.Active == false
                     select d;
          foreach (var row in data)
          {
              Console.WriteLine(row.Title);
          }
        }
      }
    }
    
  4. Now start Fiddler (download from http://fiddler2.com/) and run the console app. Fiddler will show the url generated by the console app.

share|improve this answer
    
Just to tack on a tool I find useful with Chrome is Dev HTTP Client. It hav a very simple interface for composing HTTP requests. chrome.google.com/webstore/detail/dev-http-client/… –  Robert Kaucher Jun 26 '13 at 19:09
    
Very cool! C# yes, Linq I am a little less familiar with however it's one of those on the list to learn type things so...thanks! –  Justin Jun 28 '13 at 10:36
    
Also just the general tested URL you provided worked for me which I appreciate, but even more so the examples for finding URL from console! –  Justin Jun 28 '13 at 10:38

I tried this using the 2013 api in SharePoint online, but I think the filter syntax should work the same...

You need to specify your boolean field as 1 or zero, like this...

https://mysite.sharepoint.com/_api/web/lists/getbytitle('defects')/items?$select=Color,Title,ID&$filter=Color eq 'Red' and Active eq 1&$top=100

Also, make sure you are using internal names, not display names.

share|improve this answer
    
I used the ODATA Query Builder from the SharePoint Online App Store to construct this. An awesome tool, although it does not seem to support boolean fields (And no, I am not affiliated with it). –  Derek Gusoff Jun 26 '13 at 17:54
    
Thanks...I assume that tool is only available in SP2013 since you mentioned app store? The link you provided worked but so did false from previous answer...I suppose at least in sp2010you can use either? –  Justin Jun 28 '13 at 10:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.