Skip Ribbon Commands
Skip to main content

Laura Rogers @WonderLaura

:

Quick Launch

Laura Rogers @WonderLaura > Posts > Query String URLs are like, SO Useful! (Part 1 of 4)
Hi everyone,
My blog now has a new URL!
You can now find me at http://www.wonderlaura.com
May 20
Query String URLs are like, SO Useful! (Part 1 of 4)

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:CropperCapture[110]

  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:

    connect
  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.
    CropperCapture[115]
    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:
    CropperCapture[116]

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: ,

Comments

waldemar.moes@bugaboo.com

Hi Laura,  I was wondering: This al works great, however I cannot get this concept to work when url-filtering a list on a  lookup column that is retrieved from an external content type.  Do you happen to know if this is simply impossible? Can you only filter on "native" columns and not lookup columns or just not when they are filled using an item picker from an external content type? Or is there a work-around?  Much obliged,  Waldemar
Shane YoungNo presence information on 11/8/2010 7:37 AM

forbesn@chiefind.com

I have SharePoint 2010 (enterprise).  I have set up the Productivity Hub.  I have added my own document library for content we have written.  I added a Product column to the library and the choices match the produt choices in the Productivity Hub (Excel, Word, etc.)   I have added a web part to the products.aspx page that displays the library.  I want to filter the contents that displays based upon the Product parameter in the querystring.  (/Pages/Product.aspx?Product=Excel)  I can't find the query string url filter listed in any of the web part choices.  Is there a way to modify the filter on the view to reference the query string parameter?  Other ideas?
Shane YoungNo presence information on 11/24/2010 11:51 AM

Laura

Waldemar, I believe the external content type column is storing some other value, not just the obvious field's value that you'd think.  Just like with lookup columns, when the value being stored is some long convoluted string.  So, if you knew the actual filter value then yes you could probably filter by it.  forbesn, This web part is part of the enterprise version of the product, so make sure that you have the enterprise features enabled at the site collection and site level.
Laura RogersNo presence information on 11/30/2010 8:47 PM

John Jayaseelan

Hi,         I have an issue here, I have a blog in SharePoint 2010.When I'm redirected from a custom web part to /BlogName/Lists/Posts/Newpost.aspx page I should be able to select one(Events) category automatically.   For Eg: If I am passing a query string as ../Blogname/Lists/Posts/Newpost.aspx?Status=Events, the Category should be selected as Events in the NewPost.aspx page.  Is this Possible.  regards,  John Jay
Shane YoungNo presence information on 8/16/2011 2:09 AM

Laura

John, That sounds like a good idea, but I've been burned badly any time I've messed with newpost or any of the default pages in a sharepoint blog.  I don't know the answer, and I highly recommend trying it on a test server if you are testing it.    </Laura with a broken blog site because she messed with it>
Laura RogersNo presence information on 8/19/2011 9:06 PM

Tina

Hi Laura,  Love the tutorials.  I am hoping you can help me resolve an issue I am having when I try to configure the connection.  I have added the list and the url filter but the consumer field name that I want to link to is not showing in the list.  It is a lookup field to another list.  I am running sharepoint 2010 enterprise edition.  Any suggestions?  Thanks. Tina
Shane YoungNo presence information on 8/24/2011 1:04 PM

Developer

This is all very nice but how do you pass more than 1 parameter using QueryString filter Web Part? Can anyone in the entire SharePoint community answer this simple question. Something that can be done on any other platform with minimum of fuss.
Shane YoungNo presence information on 8/31/2011 8:33 AM

Laura

Tina, Which step are you on? I can't think of why a certain field wouldn't show there.  Developer, Just use my instructions in this post http://www.sharepoint911.com/blogs/laura/Lists/Posts/ViewPost.aspx?ID=81 and do it as a data view web part instead.  Then, you can pass as many parameters as you want.
Laura RogersNo presence information on 9/3/2011 8:11 PM

Yaron

Hi Laura,  I have exaclty a page like yours, I am filtering with the field title as all my connected lists with lookup to the main list bt the Title column, so user understands what to connect to.   The Problem is when you have many items in some of the lists in the page although you can limit the number of items returned from Sharepoint the user should be able to see all items related to the current project. If you use Paging in the web part you are losing the filter Param as soon as you click the next page.   Can you think of a solution for that problem?   Best Regards, Yaron
Shane YoungNo presence information on 9/15/2011 6:36 AM

Laura

Yaron, Sorry, I can't replicate that behavior.  I don't know why yours is doing that. 
Laura RogersNo presence information on 9/21/2011 9:50 PM

ali.king

re step 9, for your 30 departments, do you literally mean create 30 explicit links:  http://mySharepoint/Forms/AllItems.aspx?department=one ...  http://mySharepoint/Forms/AllItems.aspx?department=thirty  That's not that much better than creating 30 views is it? Or is the point to just understand the url query web part?
Shane YoungNo presence information on 12/8/2011 6:21 AM

Laura

Ali.King, Yes, you'd create 30 explicit links, and the reason it is useful is that when something needs to change in that view, you only need to change it once, and not 30 times. 
Laura RogersNo presence information on 12/19/2011 10:00 AM
​I have disabled any new comments on this, because my blog has moved to a new site.  Please go here: http://www.wonderlaura.com
RSS FeedFacebookYouTube
 

 Our Books for End Users