4
votes

It seems my following query is failing and throwing "Cannot complete this action".However when I test this query in CAML Query builder it's working fine.

<Where>
    <And>
       <Or>
         <Eq><FieldRef Name='Participant' /><Value Type='User'>Test1</Value></Eq>
         <Eq><FieldRef Name='Participant' /><Value Type='User'>Test2</Value></Eq>
         <Eq><FieldRef Name='Participant' /><Value Type='User'>Test3</Value></Eq>
        </Or>
      <Eq><FieldRef Name='Department' /><Value Type='Text'>Positioning</Value></Eq>
     </And>
 </Where>
1

1 Answers

10
votes

Its seem to your query there are more than two condition on <OR> tab.You can only have a maximum of two conditions within an <Or> or an <And> tag.

This element can be nested inside other And and Or elements. The server supports unlimited complicated queries. However, any given And element can have only two conjuncts; that is, only two child elements. If you need to conjoin three or more conditions, you must nest the And elements, as demonstrated by the third example in the following section.

please see here : MSDN

So you would need to rewrite your query like:

<Where>
  <And>
     <Or>
        <Eq>
           <FieldRef Name='Participant' />
           <Value Type='User'>Test1</Value>
        </Eq>
        <Or>
           <Eq>
              <FieldRef Name='Participant' />
              <Value Type='User'>Test2</Value>
           </Eq>
           <Eq>
              <FieldRef Name='Participant' />
              <Value Type='User'>Test3</Value>
           </Eq>
        </Or>
     </Or>
     <Eq>
        <FieldRef Name='Title' />
        <Value Type='Text'>Postiioning</Value>
     </Eq>
  </And>
 </Where>