Filtering Tasks based on User or Group in SharePoint

SharePoint_2010_Logo

Task list are commonly used by workflows (i.e OOTB SharePoint Workflows, Nintex Workflows etc.) within SharePoint. In some scenarios developers uses same tasks list for managing tasks for different workflows to provide end-users to interact with all their pending tasks  from one screen.These tasks may be assigned to any individual or any group of users.In this case a user filter needs to be implemented so that user can see tasks only assigned to him or assigned to any user group that he/she belongs to.  

Filtering data based on single user is easy but to filter data based on group user belongs to may be challenging for some people. To achieve this you need to use Membership Element (query). Below is the CAML query you can use to show filtered data (i.e. Assigned to current logged in user only). You can check how to apply CAML filters on List View in SharePoint here.


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

I hope this post helps you. Please let me know in case of any concerns in comments below.

No comments:

Post a Comment