8

I want to build a CAML - Query using the IN - Tag. The queried Column is a lookup-field to a Title of another list. When I query using the text-property everything works fine:

   <Where>
      <In>
         <FieldRef Name='page' />
         <Values>
            <Value Type='Lookup'>page1</Value>
            <Value Type='Lookup'>page2</Value>
            <Value Type='Lookup'>page3</Value>
         </Values>
      </In>
   </Where>

This is giving me the wanted result: All rows with Lookups to page1, page2 oder page3 are returned.

When I try to achieve this using the IDs instead I get no results at all:

<Where>
      <In>
         <FieldRef Name='page' LookupId='True' />
         <Values>
            <Value Type='Lookup'>5</Value>
            <Value Type='Lookup'>4</Value>
            <Value Type='Lookup'>3</Value>
         </Values>
      </In>
   </Where>

I rechecked the IDs a dozen times. They are correct. When I change the query to multiple OR-Operations it works fine.

Is this a known limitation of SharePoint 2010 or do I just have to insert a "magic" word somewhere?

  • 3
    make Type='Integer' instead of Lookup: <Value Type='Integer'>5</Value>, – Arsalan Adam Khatri Oct 30 '12 at 13:28
8

make Type='Integer' instead of Lookup: <Value Type='Integer'>5</Value>

  • hi, could you please advise how to make "IN" operator query with standard field FileRef in document libraries? thank you – Michal Hainc Feb 9 '18 at 10:13
  • @MichalHainc it should be the same way as written in the question, it shouldn't be any different for document libraries! – Arsalan Adam Khatri Feb 9 '18 at 13:09
  • I tried both ways mentioned in the question with FileRef field which is supposes to be of type lookup (to which list though?) But it doesnt seem to work – Michal Hainc Feb 9 '18 at 15:39
  • Oh sorry, I didn't read that you need to use "FileRef" field.. I will check once I'm on SharePoint environment and let you know – Arsalan Adam Khatri Feb 9 '18 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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