John John
John John

Reputation: 1

CAML query with 4 conditions will raise this error "Cannot complete this action.\n\nPlease try again."

I have the following CAML query:-

<View Scope=\"RecursiveAll\"><Query><Where>
<And>
<Contains><FieldRef Name =\"ProjectStage1\" /><Value Type = \"Choice\">closed</Value></Contains>
<Eq><FieldRef Name =\"ProjectPriority1\" /><Value Type = \"Choice\">(1) High</Value></Eq>
<And>
<Leq><FieldRef Name=\"Modified\" /><Value Type=\"DateTime\" IncludeTimeValue=\"False\"><Today OffsetDays=\"-7\"/></Value></Leq>
<Geq><FieldRef Name=\"Modified\" /><Value Type=\"DateTime\" IncludeTimeValue=\"False\"><Today OffsetDays=\"-14\"/></Value></Geq>
</And></And>
</Where></Query></View>

But i am getting this error :-

Cannot complete this action.\n\nPlease try again.

can anyone advice?

Upvotes: 1

Views: 988

Answers (1)

Adam
Adam

Reputation: 840

I am not sure but I think you are missing one <And> tag in the query.

Please make sure it fallows the rules defined here MSDN - AND.

I didn't have possibility to double check it but maybe something like this should work:

<View Scope=\"RecursiveAll\">
    <Query>
        <Where>
            <And>
                <Contains>
                    <FieldRef Name =\"ProjectStage1\" />
                    <Value Type = \"Choice\">closed</Value>
                </Contains>
                <And>
                    <Eq>
                        <FieldRef Name =\"ProjectPriority1\" />
                        <Value Type = \"Choice\">(1) High</Value>
                    </Eq>
                    <And>
                        <Leq>
                            <FieldRef Name=\"Modified\" />
                            <Value Type=\"DateTime\" IncludeTimeValue=\"False\">
                                <Today OffsetDays=\"-7\"/>
                            </Value>
                        </Leq>
                        <Geq>
                            <FieldRef Name=\"Modified\" />
                            <Value Type=\"DateTime\" IncludeTimeValue=\"False\">
                                <Today OffsetDays=\"-14\"/>
                            </Value>
                        </Geq>
                    </And>
                </And>
            </And>
        </Where>
    </Query>
</View>

Basically we should fallow these kind of rules when multiple And conditions:

1. Single Condition

<Where>     
            <Eq><FieldRef Name=’Name’ /> <Value Type=’Text’>Aasai</Value></Eq>
</Where>

2. Two Condtion
<Where>
          <And>
            <Eq><FieldRef Name=’Title’ />  <Value Type=’Text’>Mr</Value></Eq>
            <Eq><FieldRef Name=’Name’ /> <Value Type=’Text’>Aasai</Value></Eq>
         </And>
</Where>

 3. Three Condtion
 <Where>
      <And>
         <And>
            <Eq><FieldRef Name=’Title’ />  <Value Type=’Text’>Mr</Value></Eq>
            <Eq><FieldRef Name=’Name’ /> <Value Type=’Text’>Aasai</Value></Eq>
         </And>
         <Eq><FieldRef Name=’Address’ /> <Value Type=’Text’>Chennai</Value></Eq>
      </And>
   </Where>

4. Four Condtion
<Where>
      <And>
         <And>
            <Eq><FieldRef Name=’Title’ />  <Value Type=’Text’>Mr</Value></Eq>
            <Eq><FieldRef Name=’Name’ /> <Value Type=’Text’>Aasai</Value></Eq>
         </And>
        <And>
         <Eq><FieldRef Name=’Address’ /> <Value Type=’Text’>Chennai</Value></Eq>
         <Eq><FieldRef Name=’Country’ /> <Value Type=’Text’>India</Value></Eq>
         </And>
      </And>
   </Where>

Upvotes: 2

Related Questions