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.


  1. Thanks for your help Marc! I am learning so much from you.

    Even better, the reference at the end of your post has exactly what I was looking for myself, a query where the user is either assigned a task based on membership in a group or assigned a task directly:

      <Membership Type=\"CurrentUserGroups\">
        <FieldRef Name=\"AssignedTo\"/>
        <FieldRef Name=\"AssignedTo\"></FieldRef>
        <Value Type=\"Integer\">
  2. Have I read this wrong or does that mean you can show items assigned to a group the user is a member of? That would made shared task lists quite powerful…say it’s so?

  3. Hi there it is nice to filter tasks assigned to a user or to its group.
    but i want to list all tasks that are assigned to users other than the current user .
    is there any way to filter out current users tasks?

  4. Believe, it should work – the only solution in the web… Unfortunately, doesn’t work for me: may be because of FBA authentication (tokens). However, I checked 2 CAML queries:

    using (SPSite site = new SPSite("http://spsite"))
    using (SPWeb web = site.OpenWeb())
    SPList lTasks = web.Lists["TaskList"];
    SPQuery qry1 = new SPQuery();
    SPQuery qry2 = new SPQuery();
    string camlquery1 = "<Where><Membership Type=\"CurrentUserGroups\"><FieldRef Name=\"AssignedTo\" /></Membership></Where>";
    string camlquery2 = "<Where><Eq><FieldRef Name=\"AssignedTo\" /><Value Type=\"Text\">" + SPContext.Current.Web.CurrentUser.Groups[0].Name+ "</Value></Eq></Where>";
    qry1.Query = camlquery1;
    qry2.Query = camlquery2;
    SPListItemCollection listItemsCollection1 = lTasks.GetItems(qry1);
    SPListItemCollection listItemsCollection2 = lTasks.GetItems(qry2); 

    The trouble is, that camlquery1 doesn’t work, while camlquery2 does :( Applied to a list, The first returns 0 items, the second returns 1 item (and is SHOULD return 1 item).

    And i need to use this CAMLquery at Schema.xml for a ListView

    • Continue researching, found the next issue:
      AssignedTo Field Value is written like:


      because it’s type is User.

      Question 1: Does

      Membership Type=”CurrentUserGroups”

      understands that type of recording GroupValue?

      Question 2: Is there any way to compare CurrentUserGroup Value with a field with type “Text” ?

  5. Solved. U wouldn’t believe, but trouble was in MultiMembership Providers and wrong Login Assigment in Custom Membership GetUser() Method…
    Sorry ^_^

  6. Hi,

    I need to filter by the author field in my list – Author’s groups = current user groups. It would be nice, if somebody could give an example of caml


Have a thought or opinion?