vineri, iunie 09, 2006

Filter List View with URL Parameter

Ok so I have tons of lists where I am tired of making a new view for every little John Doe and Jane Whatsherface that wants a new filtered view based upon the same list. There are a couple of references out there, but they are listed under some other search terms and hard to find using Google. Sharepoint would be completely useless to me if I didn't have google there, every step of the way bringing SharePoint hackers tips and tricks my way.

Anyway, on to the meat of this post:

  1. Open the page for the view you want to filter in FrontPage
  2. In design view convert the list view to XSLT (right-click, select Convert to XSLT Data View)
  3. Go into Code View (or use the Split view).
  4. Find ([CTRL-F]) the code: ParameterBinding Name="filterParam"
  5. Note that it says "Postback;Connection;" in the 'Location' field.
  6. Change the location to "Postback;Connection;QueryString(ID)" (This is case sensitive!)
  7. Note that you put "ID" as the QueryString variable. You could have just as easily put "Category" or "Subject".
  8. Go back into design view.
  9. Right-click the web part and select Data View Properties.
  10. In the 'Manage View Settings' window, click Filter.
  11. Under 'Field Name', choose the field in your web-part that you want to filter. As far as I know, it must match exactly with the name of the QueryString variable.
  12. Under 'Comparison', choose the method you want to filter by.
  13. Under 'Value', you must choose [Input Parameter].
Now, you can formulate URLs to pass a parameter to your view and filter that view based upon that parameter. Fun stuff.

Sample URL to pass the ID parameter: http://mysiteURL/subsite/lists/viewname.aspx?ID=4

Sample URL to pass a Category parameter: http://mysiteURL/subsite/lists/viewname.aspx?Category=Monkeys%20On%20Crack

Remember that once you apply the filter in Frontpage (steps 10 through 13), FrontPage will no longer display any of your data because FrontPage does not simulate any QueryString Variables. So, you need to make all your design/cosmetic changes in FrontPage prior to doing steps 10 through 13 above.

(Hint hint - Microsoft - you need to make it so that the FrontPage design view can simulate form inupt or QueryString Input so that we can see the data we would be working with if we had those filters in place!)

I have not tested passing two variables using this method. Maybe someday, although I have heard that passing two QueryString variables to a web-part is not possible. We'll see about that.

-------------------------
UPDATE: 01/31/2007:

I have passed multiple parameters!

Postback;Connection;QueryString(ID);QueryString(FirstName);QueryString(Lastname)

Note: to filter people, SP2003 likes FirstName^LastName (where ^ is a space), not ID or username.

I have a view that uses this method to filtering in all peoples who are on a project. I have a project list where people1, people2, people3 are assigned as people working on it. I have a link from the contact page like this:

http://teams.example.com/sites/QA/Lists/Regression/productivity.aspx?QATestera={@FirstName}%20{@Title}&QATesterb={@FirstName}%20{@Title}&QATesterc={@FirstName}%20{@Title}&QATesterd={@FirstName}%20{@Title}&Assigned%20To={@FirstName}%20{@Title}&ProjectManager={@FirstName}%20{@Title}

Well, I listed @Title as their last name, stupid, but oh well 'Dog with three legs doesn't make a good tripod' as we say.

Use these to filter like this:
Current = YES
Status NOT EQ COMPLETE

Then, group these user-lookup fields together:
QATestera = [Input Parameter] or
QATesterb = [Input Parameter] or
QATesterc = [Input Parameter] or
QATesterd = [Input Parameter] or
Assigned To = [Input Parameter] or

This will give you a list of projects that that user has anything to do with, not matter what the role. Just make sure to pass the role through the URL and pass it to the filter and parameterbinding.

Niciun comentariu:

Despre mine

Timi-Ostravia, Republic of Czedvia, Bulgaria
I make web applications. The tools I use are many and far between. I have been maining to learn Ruby and Python, and Perl. These tools are all like Lego to me. They can all be make to build things and have their strengths and weakest.