Posts Tagged ‘View’

Create “By My Groups” – View for a custom List

March 21, 2011 2 comments

Couple of days ago a friend of mine asked me how he can create a view on a custom list to show all items assigned to groups where logged on user is member of.

Because I am a developer the first answer was:
“Create a web part and use CAML to query the list. Use the Membership Element and you are fine.”

But he replied:
“My customer is not familiar with Visual Studio and CAML. Is there a way to achieve this task without digging deep into SharePoint stuff?”

The answer is Yes and this post describes how.

Just to make sure there are no misunderstandings: We are talking about creating a filter. It has nothing to do with security!!

If you look at a Task list you will find a view called “By My Groups”. This view is exactly what we are looking for, it displays tasks which are assigned to a group where logged on user is a member of. It does not matter if it is a SharePoint group, or an Active Directory group.


1. Creating a custom content type

It is a good idea to encapsulate your objects in a content type, so you can reuse them across you site and do not have to rebuild your lists again making mistakes and searching for typos in column names etc.

You can find more information about Content Types here.

Open “Site Actions” – “Site Settings” – “Site content types” –> Click “Create” button to create a new custom content type.


Provide a name for new Content Type and select “List Content Types” and “Task” as parent content type for your new content  type:

Update your new content type with columns you need. Be careful not to delete “Assigned To” column. We will need this column for our view later on. In this example I’ve deleted some columns and added a column “My Custom Column” to the new content type:


2. Using new content type I a list

Now it’s time to create a list and use our new content type. “By My Groups” – view is automatically available in a task list. We will use this benefit for our custom content type
instead of default task content type.

Navigate to your site and click:
“Site Actions” – “More Options” –> select the “Tasks” list template, type in a name for your list and click “Create”:


You will be automatically redirected to the default view of your new list. Click “List Settings” in the ribbon to add your new content type to your list.


Click on “Add from existing site content types” to add your new content type. If you do not see the link you have to enable content type management on your list. Click “Advanced settings” and select “Yes” in the “Content Type” section.


Select your new content type and click “Add” and “OK”


Delete built in content types which were added automatically to your list by SharePoint if you do not need them.

Testing new list and new content Type

To test our list and content type I’ve created some entries in my list. My test user “Max Mustermann” is a member of Active Directory group “ad group1” and a member of a SharePoint Group “SP Group 1”. Here is how the result of  “All Tasks” view looks like:


Switching to “By My Groups” view returns only items which are assigned to groups where “Max Mustermann” is member of:


So we’ve used built in benefits of the Task list template for our custom content type bypassing Visual Studio and working directly with CAML.

Just to make sure there are no misunderstandings: We’ve created a filter. It has nothing to do with security!!

Categories: SharePoint Tags: