0
votes

I'm trying following CAML Query but it's not working correctly instead of returning 2 documents it's returning all .

<Where><And><Or><Eq><FieldRef Name='Participant' /><Value Type='User'>Project1, test</Value></Eq><Eq><FieldRef Name='Participant' /><Value Type='User'>Project2, test</Value></Eq></Or><Eq><FieldRef Name='Department' /><Value Type='Text'>Positioning</Value></Eq></And></Where>

I've tried testing in CAML Query builder but don't find any option to add two OR with one AND conditions like above.

My full query building code is,

                strQuery1 = "<Where><And>";
                strQuery1 +="<Or>";
                foreach (string p in ParticipantNames)
                {
                    strQuery1 += "<Eq><FieldRef Name='Participant' /><Value Type='User'>" + p + "</Value></Eq>";
                }
                strQuery1 +="</Or>";
                strQuery1 += "<Eq><FieldRef Name='Department' /><Value Type='Text'>" + dept + "</Value></Eq></And></Where>";
1

1 Answers

1
votes

Have you checked how much values you are getting in 'ParticipantNames' variable? because And , Or conditions in CAML we can specify only 2 conditions, please check how many times it is looping?

<Where>
<And>
  <Or>
   <Or>
    <Eq><FieldRef Name='Participant' /><Value Type='User'>Project1, test</Value></Eq>
    <Eq><FieldRef Name='Participant' /><Value Type='User'>Project2, test</Value></Eq>
   </Or>
   <Eq><FieldRef Name='Participant' /><Value Type='User'>Project3, test</Value></Eq>
  </Or>
  <Eq><FieldRef Name='Department' /><Value Type='Text'>Positioning</Value></Eq>
</And>
</Where>