How to use User Name, User Id , Logged in User Id in SharePoint CAML Query

Ashok Raja
 
Solutions Architect
April 22, 2013
 
Rate this article
 
Views
4789

CAML query is used to retrieve data from SharePoint lists. To perform a filter based on Person or User Group or a specific user id follow any of the below approach

All the below queries are based on a SharePoint List Column named as “User ID” of type Person or Group

Option 1 –  If you know the display name of the user

 <Where>
   <Eq>
      <FieldRef Name='User_x0020_ID' />
      <Value Type='User'>System Account</Value>
   </Eq>
 </Where>

Option 2 – If you know the User Id ( not the login id)

 <Where>
    <Eq>
       <FieldRef Name='User_x0020_ID' LookupId='True'  />
       <Value Type='User'>1073741823</Value>
    </Eq>
 </Where>

Option 3 – If you would like to filter based on current user (logged in User )

 <Where>
    <Eq>
       <FieldRef Name='User_x0020_ID'/>
       <Value Type='User'><UserID/></Value>
    </Eq>
 </Where>
Category : Tips

Author Info

Ashok Raja
 
Solutions Architect
 
Rate this article
 
I am Ashok Raja, Share Point Consultant and Architect based out of Chennai, India. ...read more
 

Leave a comment