Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Consider a list which has a column of type "Person or Group" (single selection) witch contains a SharePoint group. I want to return all rows for which the group is within a list. I know the IDs of the groups so I am doing this:

<Where>
  <In>
    <FieldRef Name='GroupColumn' LookupId='TRUE' />
    <Values>
      <Value Type='User'>1</Value>
      <Value Type='User'>2</Value>
      <Value Type='User'>3</Value>
    </Values>
  </In>
</Where>

This works. But how do I write the query for which the column allows multiple selections?

From what I've found it's enough to say <Value Type='UserMulti'>1</Value> instead of <Value Type='User'>1</Value>. But this does not work and throws:

Value does not fall within the expected range.

So how do I make the query for the multiple selections field?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

There is a special element which is intended for use with multiple lookup fields:

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

Includes Element (Query)

If the specified field is a Lookup field that allows multiple values, specifies that the Value element is included in the list item for the field that is specified by the FieldRef element.

To make it work for several ID values, you have to use "Or" logic, because "In" operator supports only strict equality comparisons (i.e. it represents "Or" of "Equal"-s).

When dealing with "Or"-s, there is known inconvenience: you have to arrange the values into pairs.

Thus the final query will look like this:

<Where>
    <Or>
        <Or>
            <Includes>
                <FieldRef Name="GroupColumn" LookupId="TRUE" />
                <Value Type="Integer">1</Value>
            </Includes>
            <Includes>
                <FieldRef Name="GroupColumn" LookupId="TRUE" />
                <Value Type="Integer">2</Value>
            </Includes>
        </Or>
        <Includes>
            <FieldRef Name="GroupColumn" LookupId="TRUE" />
            <Value Type="Integer">3</Value>
        </Includes>
    </Or>
</Where>
share|improve this answer
    
Thanks omlin! Just one quick question to make sure i properly understand. If I have, let's say 20 IDs in my collection, I have to pair them all by two? –  JohnDoDo Jan 9 '12 at 10:18
    
Absolutely. You can write (or find in Google, probably) a rather simple method for arranging a collection with unknown number of items into proper CAML "Or"-s. –  Andrey Markeev Jan 9 '12 at 10:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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