Query : Only compares a pair of “values”

http://msdn.microsoft.com/en-us/library/ms196939.aspx

<And> and <Or> can only be used to compare 2 boolean expressions. Doing otherwise results in a runtime error in Sharepoint Services (described by the ever-helpful “Cannot complete this action. Please try again.” message).

For example, even though the following makes sense as a SQL construct, it will cause Sharepoint to throw an error:

<And>
<Neq>
<FieldRef Name="Status" />
<Value Type="Text">Completed</Value>
</Neq>
<Neq>
<FieldRef Name="Status" />
<Value Type="Text">5-Closed</Value>
</Neq>
<Eq>
<FieldRef Name="AssignedTo" LookupId="TRUE" />
<Value Type="int">[CurrentUser]</Value>
</Eq>
<Eq>
<FieldRef Name="IsCurrent" />
<Value Type="Boolean">1</Value>
</Eq>
</And>

In order to correctly execute the CAML must be written comparing pairs of values. For example:

<And>
<And>
<Neq>
<FieldRef Name="Status" />
<Value Type="Text">Completed</Value>
</Neq>
<Neq>
<FieldRef Name="Status" />
<Value Type="Text">5-Closed</Value>
</Neq>
</And>
<And>
<Eq>
<FieldRef Name="AssignedTo" LookupId="TRUE" />
<Value Type="int">[CurrentUser]</Value>
</Eq>
<Eq>
<FieldRef Name="IsCurrent" />
<Value Type="Boolean">1</Value>
</Eq>
</And>
</And>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s