Sunday, July 5, 2009

CAML query and Sharepoint Groups

Scenario:
Task list is one of the most commonly used list in sharepoint. But I think it is missing a view in which someone can filter what tasks are either directly assigned him or any of the Active Directory Group/SharePoint Group he belongs to.

Solution:
After some digging into CAML , I got the right CAML query for getting me exactly the same thing.

CAML

Code:

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

2 comments:

Anonymous,  November 30, 2010 at 6:16 PM  

This is a gem, Sandeep. Thank-you!
JR

nICk December 3, 2010 at 1:08 AM  

Hey this works like a charm...But the only problem is, it does not show any items to the Site Collection Administrator or any user from the owners group as they are not a part of any group. Ideally items from all groups should be visible to the SCA. It would have been better had there been a provision for this as well!