Thursday, April 19, 2007

Filter a data view by current username rather then display name

version info: Sharepoint 2003 and Frontpage 2003

I ran into a situation where a site owner wanted to restrict the items a user could see based on the current username. I am aware that using the standard data view you can filter by current user but this only works on display name which doesn't help if you have two users with the same name. So we added a username column which held 'DOMAIN\User' to identify which list items where allocated to a particular user.

Next you have to go into the web part properties for the list data view and edit the Parameter Bindings
find the line
<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>

modify this line to:

<ParameterBinding Name="UserID" Location="ServerVariable(AUTH_USER)" DefaultValue="CurrentUserName"/>



now UserID will hold the value 'DOMAIN\User' rather then 'Display Name'

Now go into the data view properties select 'Filter' add a filter where Field: Username equals [Current User]
There you have it. A List filtering on a unique domain user name rather then display name