A blog about SharePoint, Project Server and other Microsoft technologies.

Tuesday, June 9, 2015

SP2013 - Programmatically filter workflow task list for tasks assigned to current user or his group

If you are using SharePoint workflows (default or custom), you are probably using tasks and Workflow Task List. In the default view of that list, every user can approve every task in the list. This could be a big problem, because, if users have option to do something wrong, they will probably do it. Usually, the requirement is that users are allowed to see only their own tasks. If you want to do this programmatically, it is easy to make caml query that would filter tasks for a logged in user, but what if task is assigned to a SP group and current user is a member of that group? Fortunately, this is a simple task too.For this example, I created SharePoint console application in Visual Studio. This example fetches your Workflow Task List, gets the default view of that list and sets the filter on the list items. It filters tasks that are assigned to current user and tasks assigned SP groups that user is a member of. This is the code: