CAML Filter for Current Group Membership

My pal Christophe Humbert at PathToSharePoint.com forwarded me a question from one of his readers earlier today. I didn’t know the answer, but it intrigued me enough to track down the answer.

Something that a lot of people don’t realize is that every List View Web Part (LVWP) you use in your SharePoint pages contains the CAML required to render what it’s supposed to render. If you crack open the page with SharePoint Designer, you can find that CAML, copy it out, make it human readable (by changing the escaping to the real characters), and see what’s going on.

If you look at the CAML for the LVWP on the By My Groups view page in a Tasks list, you’ll see this Where clause:

<Where><Membership Type="CurrentUserGroups"><FieldRef Name="AssignedTo"/></Membership></Where>

or, formatted for humans:

<Where>
  <Membership Type="CurrentUserGroups">
    <FieldRef Name="AssignedTo"/>
  </Membership>
</Where>

If you look at the CAML schema, you can see the details for the options for Membership.  What this CAML Where clause is doing is filtering for items where the AssignedTo value exists in the the current user’s groups.  Sweet!

Frankly, this is a new one to me, but it makes sense.

Similar Posts

22 Comments

  1. What if you wanted to check against a specific group instead of the value of a column? Like a filter that checks what that a user is part of the “AdminGroup” group. How would you do that?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.