Sharepoint - CAML query for field of type "Person or Group" which allows multiple selections

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>

Tags:

User