SharePoint: Filter on Current User's Group Membership

You are likely already aware that you can apply a filter condition to a CAML query to return only items where a specified user or group field is equal to the current user.

In SharePoint's view settings UI, you would do this by filtering where the field is equal to "[Me]". The corresponding CAML query snippet (assuming "AssignedTo" as the internal name of the field) would be:


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

What is less obvious is that you can also apply a filter to return items where the field contains a group of which the current user is a member. In fact, one of the built-in list templates comes with a view that already has such a filter: the "By My Groups" view on the task list.

If you don't have access to compose your own CAML query, you can achieve the "By My Groups" view by creating a content type that inherits from the Task content type (assuming you do not delete the "AssignedTo" field).

The corresponding CAML query snippet for filtering on the current user's groups is this:

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

To take it a step further, you can compose your own composite CAML query to filter on items assigned to the current user directly OR assigned to a group in which the current user is a member:

<Or>
<Membership Type="CurrentUserGroups">
<FieldRef Name="AssignedTo" />
</Membership>
<Eq>
<FieldRef Name="AssignedTo" />
<Value Type="Integer">
<UserID/>
</Value>
</Eq>
</Or>

Add comment

biuquote
  • Comment
  • Preview
Loading

Recent Comments

Comment RSS

Post History

<<  October 2018  >>
MoTuWeThFrSaSu
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar