1
votes

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.

2

2 Answers

4
votes

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>";
1
votes

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

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