Pretty simple, huh? Well, there's one small kicker to this: this works right IF you are only using a single list. If you follow the instructions of Laura Rogers or other SharePoint gurus and create a linked data source (joining the information from 2 different lists with a common column), then this filter will not work. It will actually change the place in the "code" where the filtering happens and it just won't work. The way to fix this is to open up the page in Split or Code view and you'll have to copy-paste something from here into a specific part (don't worry, I'll show you where). The piece you need to copy to your clipboard is this:
"<View><Query><Where><Eq><FieldRef Name="YOURCOLUMNNAME"/><Value Type="Integer"><UserID/></Value></Eq></Where></Query></View>"
What this really looks like is this:
"<View>
<Query>
<Where>
<Eq>
<FieldRef Name="YOURCOLUMNNAME"/>
<Value Type="Integer">
<UserID/>
</Value>
</Eq>
</Where>
</Query>
</View>"
This is the dreaded CAML - a markup language used to get information from sharepoint lists like SQL will get information from SQL tables. What it means is that it needs to check the Field "YOURCOLUMNNAME" (which you will need to replace with the name of your person/group column that you want to filter by) and use the "UserID" integer (aka your ID number from sharepoint) to only get the ones where the ID number in that column matches yours. Where you will need to place this code, look toward the top of the code for your data view webpart and look for two things: 1) the words "SharePoint:AggregateDataSource" and several "<asp:Parameter"s. 2) just below the Aggregate data source and some of the parameters, you should see "SharePoint:SPDataSource" and toward the right you will find the phrase SelectCommand = "<View></View>" or something super close to that. Replace everything in quotes for the SelectCommand with the stuff from above. Be sure to rename the YOURCOLUMNNAME with the actual name of your column. This will filter that data source automagically for you. Hope that helps and doesn't increase brain fog.
when I copy pasted it into the correct spot it didnt work. It's like there is a syntax error right after my column name -- because the quote after it lights up. Is there a syntax error by chance? Penn
ReplyDeleteMake sure that there is one set of quotes surrounding the whole statement and not two. Also make sure there are quotes around your field name. If it freaks out, try using single quotes to go on the outside of the whole thing and leave the double quotes surrounding your field name alone or vice versa
DeleteYou'll need to use:
Delete"
instead of quotes " used in example.
Hi Brendan, thanks for the post! Tried using this approach to filter by Created By field (Author). It is throwing an error...
ReplyDeleteAny help you can provide is greatlyy appreciated!
Thanks!