Filter Drop down CAML

Apr 17, 2012 at 12:54 PM
Edited Apr 17, 2012 at 1:12 PM

Hi,

I need to use nested OR CAML in Filter filter drop down. The below CAML not giving the expected result. Please help on this.
Is is possible to use nested CAML in filter drop down ?

 

Example CAML i'm using.

<Or> 
<Or>
 <Eq> <FieldRef Name='ProjectName'/> <Value Type='Text'>Test</Value> </Eq>
 <Eq> <FieldRef Name='ProjectName'/> <Value Type='Text'>Project2</Value> </Eq> 
</Or>
 <Eq> <FieldRef Name='ProjectName'/> <Value Type='Text'>Project3</Value> </Eq>
 <Eq> <FieldRef Name='ProjectName'/> <Value Type='Text'>Sample</Value> </Eq>
</Or>

Thanx in advance :)
Apr 17, 2012 at 1:46 PM

It's not entirely clear what logical statement you are trying to make here but you are missing some syntax. For now I'll assume that you want the CAML query to return ProjectNames with values that are equal to either (Test & Project2) OR (Project3 & Sample). In that case the CAML syntax will be as follows:

      <Or>
<And> <Eq> <FieldRef Name='ProjectName' /> <Value Type='Text'>Test</Value> </Eq> <Eq> <FieldRef Name='ProjectName' /> <Value Type='Text'>Project2</Value> </Eq> </And> <And> <Eq> <FieldRef Name='ProjectName' /> <Value Type='Text'>Project3</Value> </Eq> <Eq> <FieldRef Name='ProjectName' /> <Value Type='Text'>Sample</Value> </Eq> </And> </Or>

Try that and see if it returns the expected results.

Coordinator
Apr 17, 2012 at 8:45 PM
Edited Apr 17, 2012 at 8:45 PM

Raathigesh:

You might want to look into using the U2U CAML Builder to help you get it right.

M.

Apr 18, 2012 at 5:24 AM

Thanx all for the reply. I figured out the the problem. CAML  Operators accepts 2 Child Operators in it. The below modified CAML Worked fine.

<Or> 
<Or>
<Or>
 <Eq> <FieldRef Name='ProjectName'/> <Value Type='Text'>Test</Value> </Eq>
 <Eq> <FieldRef Name='ProjectName'/> <Value Type='Text'>Project2</Value> </Eq> 
</Or>
 <Eq> <FieldRef Name='ProjectName'/> <Value Type='Text'>Project3</Value> </Eq>
</Or>
 <Eq> <FieldRef Name='ProjectName'/> <Value Type='Text'>Sample</Value> </Eq>
</Or>

U2U CAML Builder also helped alot to get familiar with CAML.

Thanks alot sympmarc for the awesome library. :)