This project has moved and is read-only. For the latest updates, please go here.

Dynamic CAML filter: All Items

Aug 5, 2010 at 12:57 PM


I'm looking for a dynamic CAML filter that should filter a list either on a specific value OR return all items. The real query is a bit more complicated but the main thing I'm looking for is

Return the variation with the value set by the variable variationFilter

<Where<Eq><FieldRef Name="Variation" /><Value Type="LookupMulti">'+variationFilter+'</Value></Eq></Where>

Can I set the variableFilter to a specific value so it matches all Items (like *, % or something else)?


Aug 5, 2010 at 1:30 PM

Multiselect columns are tricky, *and* you seem to want to do wildcard matching. I don't think that CAML supports any wildcarding, but I could be wrong about that.  You're probably going to be better off grabbing a larger result set and doing the filtering in script rather than CAML.

The other suggestion I'd have is to set up a List View Web Part which approximates how you'd like to filter things. Than you can carck open the page in SharePoint Designer and look at the CAML which ends up embedded in the LVWP as a reference. You can also try the U2U CAML Builder.

Here's a link to the CAML Core Schemas:


Aug 5, 2010 at 1:36 PM

Just checked in U2U CAML Builder, and this should work:

<Query><Where><Contains><FieldRef Name="PostCategory" /><Value Type="LookupMulti">Home</Value></Contains></Where></Query>

Aug 5, 2010 at 2:13 PM

What I needed was a wildcard matching all list elements, like if you write the following with the <value> empty

<Query><Where><Contains><FieldRef Name="PostCategory" /><Value Type="LookupMulti"></Value></Contains></Where></Query>

it should return all list items, unfortunately that doesn'work

Aug 5, 2010 at 2:22 PM

So you're trying to match if the multiselect column contains a specific value *OR* is null?

            <FieldRef Name='PostCategory' />
            <Value Type='LookupMulti'>Home</Value>
            <FieldRef Name='PostCategory' />
Aug 5, 2010 at 2:36 PM

No, I have a filter value set by the javascript variable "variationFilter"

<Where<Eq><FieldRef Name="PostCategory" /><Value Type="LookupMulti">'+variationFilter+'</Value></Eq></Where>

When variationFilter is set to Home it matches all items with the PostCategory set to "Home" - nothing strange here

When variationFilter is set to nothing (or a value matching all items) it should return all items => it should then not filter on the column PostCategory at all 

The reason is I only wanted one CAML query doesn't matter if I want to return all items or just a filtered view. Looked around quite much for this and can't find anything, guess it might not be possible...

Aug 5, 2010 at 2:40 PM

It sounds like what you need to do is simply build up the CAMLQuery string conditionally. Or am I missing something else?


Aug 5, 2010 at 2:46 PM

Guess that's my only choice, just hoped for an easier solution. Tnx for your help


Aug 5, 2010 at 2:48 PM

That is the easy solution, IMHO. That's the way I do it in the SPServices functions.