0

I have a custom content type in the Pages library of a publishing site, which contains two multi-value taxonomy fields. I'm trying to write a CAML query that will return any items from the Pages library that contain specific values in either of those taxonomy fields, i.e. return any items where taxonomy field 1 = 'X' or taxonomy field 2 = 'Y', so I'm using In clauses within an Or clause in my CAML query. The weird thing is that the In clause appears to be behaving like an And clause. For example the following CAML query only returns items when both the NewsLocation field contains the value in the first In clause AND the OperatingCompany field contains the value in the second In clause.

<Where>
  <Or>
    <In>
      <FieldRef LookupId='True' Name='NewsLocation' />
      <Values>
        <Value Type='Integer'>1</Value>
      </Values>
    </In>
    <In>
      <FieldRef LookupId='True' Name='OperatingCompany' />
      <Values>
        <Value Type='Integer'>3</Value>
      </Values>
    </In>
  </Or>
</Where>

Have I got the CAML syntax wrong, or is there an issue with how In clauses work in Or clauses?

4
  • Hi Eric, I'm not sure I follow. The In clause in your comment only differs from mine in that it has two Value nodes instead of one. My CAML snippet is a simplified example, hence I didn't use more than one Value clause in each In clause. Jul 29, 2016 at 16:15
  • I think your In statement is wrong, I search into my codes and I found a caml used time ago and this have the next format: <where><in><fieldref name="ID"><values><value type="Counter">1</value></values></fieldref></in></where> If you see the fieldref tag enclose the values tag.
    – Marco
    Jul 29, 2016 at 16:22
  • Hi Marco, my In clause syntax is correct - both In cluses in my example return the expected data if they are run separately. It's only when both are included in an Or clause that the query as a whole stops working as expected Jul 29, 2016 at 16:41
  • Why are you using <In> instead of <Eq> when you only have one value in each?
    – Erin L
    Jul 29, 2016 at 20:22

1 Answer 1

0

It looks like you're experiencing the same issue seen in this StackExchange post: Sharepoint CAML Query IN operator

The author of this post was also trying to use In inside of an Or clause. He thought that the issue might be a bug with LookupID because he was able to resolve the issue by searching against the text values:

<Where>
<Or>
<In>
        <FieldRef Name="COLUMN1"/>
        <Values>
          <Value Type='Text'>VALUE1</Value>
          <Value Type='Text'>VALUE2</Value>
        </Values>
      </In>
<In>
        <FieldRef Name="COLUMN2"/>
        <Values>
          <Value Type='Text'>VALUE3</Value>
          <Value Type='Text'>VALUE4</Value>
        </Values>
      </In>
</Or>
</Where>

This strategy returned the correct results for him. Are you able to use text values or is using the IDs a requirement?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.