It's strange that CAML query can only compare a pair of expressions either by <And> or <Or>. So if you have a query like the one follows, you will see an error message "Cannot complete this action. Please try again", which is not very helpful.
<Where>
<And>
<Gt>
<FieldRef Name='Created' /><Value Type='DateTime'><Today OffsetDays='-30' /></Value>
</Gt>
<Neq>
<FieldRef Name='ContentType' /><Value Type='Text'>Folder</Value>
</Neq>
<Neq>
<FieldRef Name='ContentType' /><Value Type='Text'>InfoPath Form Template</Value>
</Neq>
</And>
</Where>
The workaround is to use nested <And> or <Or>, in which each operator only takes two expressions. The following snippet corrects the above one. This will make things more complicate especially for a number of conditions mixed with <And> and <Or>.
<Where>
<And>
<And>
<Gt>
<FieldRef Name='Created' /><Value Type='DateTime'><Today OffsetDays='-30' /></Value>
</Gt>
<Neq>
<FieldRef Name='ContentType' /><Value Type='Text'>Folder</Value>
</Neq>
</And>
<Neq>
<FieldRef Name='ContentType' /><Value Type='Text'>InfoPath Form Template</Value>
</Neq>
</And>
</Where>
Posted
11-27-2007 10:31 AM
by
jasonwj