09 November, 2006

Filter list views based on user profile properties

MOSS 2007 comes with a number of filter web parts that makes it really easy to filter your SharePoint lists by connecting filter web parts with list view web parts. Out of the box, there are 10 filter web parts available.

There's one new filter web part in particular I find very powerful, the Current User Filter. With the Current User Filter you can filter the contents of web parts by using any property of the current user.

As an example of its use, imagine you build a corporate asset register based on a custom list. One of the columns, 'Asset Location', records which office the asset is located at. You also create a number of views to ease the management of the asset register (e.g. group by asset type, sort by purchase date, etc.).

For each local office, you nominate a person to look after the asset register for the local office. That person is only ever going to be concerned with the assets in the local office, so to make life easier for that person, you want to hide asset records from other offices.

Providing that the users have their Office property set in their user profile (imported from AD), you can use the Current User Filter web part to filter the asset register. Because all list views in SharePoint 2007 are proper web part pages, you can add the Current User Filter to all the views you have created for the asset register.

In the web part properties for the Current User Filter you can specify which user profile property to use (in this case 'Office'). You then simply connect the two web parts by sending the filter value from the Current User Filter to the appropriate column (in this case 'Asset Location') in the list view web part.

What you end up with is a central corporate asset register easing aggregated reporting. However, for the local asset manager at each office, it appears to be a local asset register only showing local assets.

Considering you can define your own user profile properties, there are unlimited opportunities for personalising list views. And because all list views now are web part pages, you can extend that personalisation to all the views of a list.

Stay tuned to my SharePoint musings: Subscribe via email or RSS.


Dr_Malito said...

How can I modify the fields in the user profiles?

Kristian Kalsing said...

You can access the user profiles on the Shared Services pages through SharePoint Central Administration.

Anonymous said...

I'm trying to filter a document library (which I added the office attribute) but the only attributes I can connect via is "type" and "modified by". How can I extend thoose choices to other attributes of my document library (such as office)?

Anonymous said...

Can I find this web part for WSS 2003?

Kristian Kalsing said...

No, these web parts are only available in MOSS 2007 Enterprise version.

MMiller said...

Can the Current User Filter be applied against a KPI Details Web Part? My KPI shows Average Hours worked by a group of employees. The KPI gets the average hours from a Pivot Table in an Excel File, where one of the filters is the employee's Supervisor. I want to filter this down based on the Current User, who would be the Supervisor of some, but not all of the employees in the pivot table. Based on this Current User filter, the Average Hours calculation should vary based on which Supervisor is currently signed into the Site.

M. Hassan Raza said...

Thanks mate.


machewd said...

Thanks so much for posting this solution. It worked perfectly!

seemebreakthis said...

This is perfect! One thing I've found that I'd like to share with others is that the list will need to be configured in a view with 'standard view' view type (as opposed to say 'dynamic view' or 'access view') for this filter to work properly. Otherwise you cannot make a connection to the filter at all. That took me some time to figure out.

ybot said...

Hi, I've created a profile property but I can't suceed in displaying it in the current filter web part properties. My list of profile properties for current users is empty and I can only select the current user name. What must I do to enable my profile property in this list?

Many thanks,

Ben McInerney said...

Hi Kristian,

Well, the Current User Filter WP works a treat on a standard list view of a list, but cannot connect to a Calendar View webpart on the same list !?!?!?
Any ideas why? I have searched to no avail!
[I am trying to show only items in the calendar where the items have the same department value as the user.]

Sowmya said...

Hi Kristian,

I am involved in SharePoint developement with Filenet.
would want to know is there any method of getting the Logged in User credentials(password).
Authertication Mode: Windows


tony.harris said...

Does this mean that if my data is in an external data source (SQL Server, for example) that a call to a SQL database, using the BDC, would be required to return ALL records prior to being filtered by the webpart?

Anonymous said...

Hi. Good Post.
Well actually my requirement is that i want to filter my List web part using Current User Web Part on a column which i dont want to show in my list View.Means the column is present in my list but I'm not showing the column.
Is this possible??


Kristian Kalsing said...

You need to include the column you want to filter on in the view. But you can use SharePoint Designer to hide columns you don't want to have displayed. Use style="display:none" in the column you want to hide.

Aditi said...

Thanks :-) It helped.
I'm facing one more problem.
For my list I've set the Advanced permission as User can see only their own Items.I've changed the look & feel of my list using Sharepoint designer by converting it into XSLT data view.So now when the User comes in create a item in the list,the Full Toolbar on the top just goes off. only 1 row with all Column names is seen.
If there is no item in the list,then only m facing this problem.
Do you have any idea how can i solve this problem?
Thanks in advance..

Anonymous said...

I tried to use the current user profile combined with a dataview web part the filtering works perfectly.

But when I apply the pagination in the data view web part, the pagination only works for the first two pages after that the pagination just keep showing the same sets of data. If i remove the current user filter / the pagination it's working fine. Do you have any ideas why does the current user filter and the dataview web part pagination cannot work together?

Kristian Kalsing said...

I just tested this with pagination on the data view. I encountered the same issue that the pagination does not work beyond the first two pages. Must be a bug...

Sorabh Kumar said...

How can i filter Profiles based on profile type. I have some accounts/profiles(different users). I want to filter them based on their types.I am using elgg. Please help me out.