Nicolae Anghel
Nicolae Anghel

Reputation: 41

SharePoint CAML query not working when using OR and IN

I'm trying to query a SharePoint list with the following query:

<Where>
<Or>
 <In>
    <FieldRef Name='col1' />
    <Values><Value Type='Integer'>1</Value></Values>
 </In>
 <In>
    <FieldRef Name='col2' />
    <Values><Value Type='Integer'>1</Value></Values>
 </In>
</Or>
</Where>

Both are Taxonomy fields. The problem is I'm not getting any results. When using just one of the conditions I get results, but when combining them with "Or" I don't get any results. What am I doing wrong?

EDIT: I'm using SharePoint 2013 and I've also tried to add LookupId="TRUE"

Upvotes: 0

Views: 787

Answers (3)

Nicolae Anghel
Nicolae Anghel

Reputation: 41

I ended up querying on the hidden TextFields of the Taxonomy fields, by using the term ids:

<Where>
<Or>
  <Contains><FieldRef Name='kf7aa880952e4699a9693b8b7379c884'/><Value Type='Text'>40e7b1fd-3892-4311-8428-6dbe77fc4ad7</Value></Contains>
  <Contains><FieldRef Name='le11567cdf314372b377761db5f67b84'/><Value Type='Text'>40e7b1fd-3892-4311-8428-6dbe77fc4ad7</Value></Contains>
</Or>
</Where>

Upvotes: 1

Truezplaya
Truezplaya

Reputation: 1313

I would suggest using CAML builder to build up your query.

Try the following

    <Where>
<Or>
 <In>
    <FieldRef Name='col1' />
    <Values><Value Type='Text'>TAxTextValue</Value></Values>
 </In>
 <In>
    <FieldRef Name='col2' />
    <Values><Value Type='Text'>TAxTextValue</Value></Values>
 </In>
</Or>
</Where>

Someone has pointed out there may be a bug but you haven't indicated a version of SP.

Possible bug

Thanks

Truez

Upvotes: 0

Pratik Chotai
Pratik Chotai

Reputation: 28

try something like this

<FieldRef LookupId='TRUE' Name='MyTaxonomyField' />
<Values>
 <Value Type='Integer'>4</Value>
</Values>

Upvotes: 0

Related Questions