Filter on current user with CAML Query.


Hi everybody,

Today I will give you a little trick with CAML Query: how to retrieve the current user.

Logic suggests that we write a query like this:

 <Eq> <FieldRef Name='AssignedTo' /> <value Type='User'> [Me]</ Value> </ Eq>  

But then, it does not work …
The proper way to retrieve the current user is to change our query like this.

 <Eq><FieldRef Name='AssignedTo' /><Value Type='Integer'><UserID Type='Integer'/></Value></Eq> 


And that way we get the current user.

Christopher.

Advertisements
This entry was posted in SharePoint 2007, SharePoint 2010 and tagged , . Bookmark the permalink.

4 Responses to Filter on current user with CAML Query.

  1. EMMANA says:

    As simply as this post looks, it took me hours to stumble on this solution and my problem was resolved. Thanks Chris

  2. Ivan Krupsky says:

    Thanks, Chris… If all technical posts were so short, useful and clear! :o)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s