Reputation: 64
My question is about caml query SP2010, i've got colums as follow: Country, Role, Species, Species, Topic, Documenttype, Searchtext. There is possible that user will search by Countries (multiple->UK,France,Belgium) and type document name like Doc_num_one.txt and add other criteria like Role, Species, Species, Topic, Documenttype. I've tried different queries but I think I stucked. Below what I tried so far:
<Query>
<Where>
<In>
<FieldRef Name="Country"/>
<Values>
<Value Type="Lookup">United Kingdom</Value>
<Value Type="Lookup">Poland</Value>
<Value Type="Lookup">Belgium</Value>
</Values>
</In>
</Where>
</Query>
or
<Query>
<Where>
<And>
<Eq>
<FieldRef Name="Title" />
<Value Type="Text">doc num two</Value>
</Eq>
<Or>
<And>
<Eq>
<FieldRef Name="Country" />
<Value Type="Lookup">United Kingdom</Value>
</Eq>
<Eq>
<FieldRef Name="Role" />
<Value Type="Lookup">Super Admin</Value>
</Eq>
</And>
<And>
<Eq>
<FieldRef Name="Country" />
<Value Type="Lookup">Belgium</Value>
</Eq>
<Eq>
<FieldRef Name="Role" />
<Value Type="Lookup">Super Admin</Value>
</Eq>
</And>
<And>
<Eq>
<FieldRef Name="Country" />
<Value Type="Lookup">Poland</Value>
</Eq>
<Eq>
<FieldRef Name="Role" />
<Value Type="Lookup">Super Admin</Value>
</Eq>
</And>
</Or>
</And>
</Where>
</Query>
Solution:
<Query>
<Where>
<And>
<In>
<FieldRef Name="Country"/>
<Values>
<Value Type="Lookup">United Kingdom</Value>
<Value Type="Lookup">Poland</Value>
<Value Type="Lookup">Belgium</Value>
</Values>
</In>
<In>
<FieldRef Name="Role"/>
<Values>
<Value Type="Lookup">Super Admin</Value>
<Value Type="Lookup">Admin</Value>
<Value Type="Lookup">User</Value>
</Values>
</In>
</And>
</Where>
</Query>
Upvotes: 0
Views: 987
Reputation: 4247
The second query does not work because it has more than two child elements within the <Or>
element. If you want to test more sub-conditions, you have to introduce helper elements:
<Or>
<And>...</And>
<And>...</And>
<And>...</And>
<And>...</And>
<And>...</And>
</Or>
becomes
<Or>
<And>...</And>
<Or>
<And>...</And>
<Or>
<And>...</And>
<Or>
<And>...</And>
<And>...</And>
</Or>
</Or>
</Or>
</Or>
The same applies to <And>
elements.
Upvotes: 1