Query SharePoint List using a Person field

Query SharePoint List using a Person field

That is because we want to filter the list using the user name or display name.
Now if you go to the CAML editor instead of Query builder, we can see the below query

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<Query>
<Lists>
<List ID="{3F6D13BE-4A48-4871-9EF1-FA07B28C77DC}" />
</Lists>
<ViewFields>
<FieldRef Name="LinkFilename" />
</ViewFields>
<Where>
<Eq>
<FieldRef Name="CheckoutUser" LookupId="TRUE" />
<Value Type="User">{WorkflowVariable:userCheckedOut}</Value>
</Eq>
</Where>
</Query>

The mistake is we are trying to query using a SharePoint User Id instead of only name (you can see in the queryLookupId=”True”).
Remove LookupId=”True” and execute the query. It will work now and return the file name. We can send out the notification to the user with this collection of file name.