SPKan
SPKan

Reputation: 555

CAML person or Group field with Multiple values

I have a Field with Name TargetedPeople in a Sharepoint list. This is a Person or User group which can have multiple values.

The CAML I used for Querying is

siteDataQuery.Query = @"<Where><Includes><FieldRef Name='TargetedPeople' LookupId='TRUE'/><Value Type='Integer'>" + webInContext.CurrentUser.ID + "</Value></Includes></Where>";

This works fine if we have set the Allow Multiple Selections for "No" in the field. But this seems like not working for if it set to "Yes".

Please share me how to query a multiple field.

Upvotes: 1

Views: 5868

Answers (2)

Adrian Stanisławski
Adrian Stanisławski

Reputation: 755

Also works and looks like simpler (tested on SP Online):

<Contains>
    <FieldRef Name='TargetedPeople' />
    <Value Type="Integer">
        <UserID Type="Integer" />
    </Value>
</Contains>

Upvotes: 1

SPKan
SPKan

Reputation: 555

After some changes I was able to figure out this. If the field has multiple values we should define the value Type as LookupMulti. Following is the working code sample

siteDataQuery.Query = @"<Where><Contains><FieldRef Name='TargetedPeople' LookupId='TRUE'/><Value Type='LookupMulti'>" + webInContext.CurrentUser.ID + "</Value></Contains></Where>";

Upvotes: 4

Related Questions