Site icon @WonderLaura

Query String URLs are like, SO Useful! (Part 1 of 4)

Advertisements

In this blog post, I’ll not only explain what Query String URL Filter web parts are, but what the whole concept is behind query strings, and some ways to make use of them in SharePoint.  First of all, what is a query string?  Basically, it’s a part of a URL that contains a filter, to send filter information to the page that you’re viewing.  These are used all over the place on the web, not just in SharePoint.  The basic syntax consists of a question mark followed by a word, and the “equals” something.  So, if you are looking at a web page that consists of information pertaining to the marketing department, your URL could end with this query string:

?Department=Marketing

In SharePoint, if you have MOSS Enterprise, there’s an out-of-box web part called the Query String URL Filter.  But, as I will show you later, you can still do query string filtering if you don’t have MOSS Enterprise.

So begins the love story between me and query strings…

The first time I used them was when I created a policy management system in SharePoint.  Picture this, a library of policies, with a Department column in the library, and each policy was associated with a department name.  To create a list of policies for each department, you could create multiple views on the library, with each view just being filtered by the Department column being equal to ___ (each department name).  Well, I didn’t want to do this, because I didn’t want to have to go back and modify 30 different views if the business owner decided that a column needed to be added or something.  So, instead, I did this:

  1. Go to the default view URL:
    http://contoso/policies/PolicyList/Forms/AllItems.aspx
    Click Site Actions and Edit Page.
  2. Insert the Query String URL Filter web part on this AllItems.aspx page, above the document library.
  3. Go into the filter web part’s properties, shown in this screenshot.
  4. In the Query String Parameter Name, put a word that describes the field you’ll be filtering by.  The Filter Name can optionally be changed, but it doesn’t really matter.
  5. Click OK in the web part tool pane.
  6. Connect the Query String URL Filter web part to the list or library web part that you’d like to filter.  In this case, it’s a list  of company policies, in which I’m going to create a filter for policies related to each department name.  At the top right corner of the filter web part, click the Edit button and choose Connections –> Send Filter Values To –> and choose the name of the library, in this case it is the Policy List, as shown in this screenshot:
  7. On the Configure Connection screen, pick the Consumer field.  The consumer web part is the one you’re sending the filter to.  The Policy List here.  I’m filtering by the Policy Department, so that’s what I pick in the drop-down box.

    Note that whatever field you filter by needs to be displayed as a column in the web part in order for it to be listed in the drop-down box on this screen.  If you’d like to filter by a column and NOT display it in the web part, that consumer web part needs to be a data view web part.
  8. Click Finish and Exit Edit Mode.
  9. Manually create a link to each department’s list of policies.  Put these in a links list or in the Quick Launch or wherever.  Here’s an example of what the filtered list of IT policies looks like:

Notice a couple of things.  See that the Policy Department field shows that little filter icon, and it shows only the IT policies.  Also notice the URL.  It is:

http://moss:16071/policies/PolicyList/Forms/AllItems.aspx?department=it

Note: If you insert this web part on your default view, just remember that when new views are created, they will be based on this default view (by default) and they will also include this extra web part, which you may need to remove from new views.

I’ve demonstrated a very basic way that the Query String URL filter can be used.  Once you understand the basic functionality, there are many more things you can do with it.  Part 2 of this 4 part series will cover a more advanced, elaborate solution.

Technorati Tags: ,


Exit mobile version