CAML Filter for Current Group Membership

My pal Christophe Humbert at 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:

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

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.