CAML query with Person or People and Groups column

Today I want to highlight CAML query with Person or People and Groups column. When we retrieve that column, we will get the result as {UserID};#{UserName} format, e.g.: 96;#Lee, Kelvin.

If you attempt to query base on the column using exactly the same format, it won’t works. Look at the following example how to query this column type.

This doesn’t works.

<Where>
<Eq><FieldRef Name='UserID' /><Value Type='User'>96;#Lee, Kelvin</Value></Eq>
</Where>

This will works. Only User Name required.

<Where>
<Eq><FieldRef Name='UserID' /><Value Type='User'>Lee, Kelvin</Value></Eq>
</Where>

This works too. Only User ID required. Must specify LookupId= ‘TRUE’

<Where>
<Eq><FieldRef Name='UserID' LookupId= 'TRUE'/><Value Type='User'>96</Value></Eq>
</Where>

Leave a Reply

Your email address will not be published. Required fields are marked *