Passing Filter Parameters Through SharePoint URLs

Here’s a neat trick I figured out the other day.  It didn’t actually solve my problem, but I figured it was worth documenting in case it comes in handy in the future.  My goal was to add filter parameters to a URL so that it would automatically filter for specific elements.

This sort of technique could be used to point users or a page viewer webpart from a project workspace back to a centralized document repository, the likes of which I described in this post.

So first off, we need the URL of the list.  Since I have the Contoso demo environment open, I’ll just use the sample report library in the BI Center.

http://project.contoso.com/PWA/ProjectBICenter/Sample%20Reports/Forms/AllItems.aspx

image

Now let’s filter on all items where Modified By = Marc Soester.  We need to identify how the system is referring to the Modified By field.  To do this, click on the Library tab, and select the Library Settings option.  Click on the Modified By field in the middle of the page.

That will yield a page that looks like this:

image

Take a look at the URL:

http://project.contoso.com/PWA/ProjectBICenter/_layouts/FldEditEx.aspx?List=%7B0AE8F9C9%2D0277%2D40DE%2DAFAB%2D25B10127CC3A%7D&Field=Editor

That last bit is what we’re looking for.  Internally, SharePoint refers to the Modified By field as the Editor field.

So now we take the original URL and add the following string:

?&FilterField1=Editor&FilterValue1=Marc%20Soester …to yield the following URL:

http://project.contoso.com/PWA/ProjectBICenter/Sample%20Reports/Forms/AllItems.aspx?&FilterField1=Editor&FilterValue1=Marc%20Soester  

Click on that, and you get a filtered list:

image

Want to filter on two fields?  Use the following syntax:

http://project.contoso.com/PWA/ProjectBICenter/Sample%20Reports/Forms/AllItems.aspx?&FilterField1=Editor&FilterValue1=System%20Account&FilterField2=DocIcon&FilterValue2=vdw

…which will filter on all Visio Drawings (VDW) created by the System Account.

image

Advertisements
Passing Filter Parameters Through SharePoint URLs

9 thoughts on “Passing Filter Parameters Through SharePoint URLs

  1. Bob says:

    Thank you
    Exactly what I was looking for.
    Now do you know of a good way to automate the building of that url so we don’t have to do the copy/paste thing?

  2. Probably the easiest way to use URL filtering (that works fine in SP2013 as well) is to temporarily set up the list view web part to include the columns you need to filter by. Then you manually select the filters you need. After that, you can more or less copy-paste the URL to where you need it. This approach works in most cases.

    Exceptions to the simple approach above are
    1. You need complex filtering logic that can not be accomplished by simply clicking around in the list view web part, or
    2. You need to filter two list view web parts on the same page. In this last case, if you try the approach above you will be able to set up filters on both web parts. But when you copy the URL to a new browser window you end up with only one of the web parts being filtered.

    So if you need something more complex, you need to either use filter web parts, or combine a simpler filter with javascript that removes the extra list items. Or you could throw the list view web part away entirely and load and render the data with javascript. That will give you full control, but you will also lose a lot of the OOTB functionality.

  3. Jon says:

    I don’t suppose there is a way to do an ‘Or’, thus in your example:

    http://project.contoso.com/PWA/ProjectBICenter/Sample%20Reports/Forms/AllItems.aspx?&FilterField1=Editor&FilterValue1=Marc%20Soester%5BOR%5DFilterField1=Editor&FilterValue1=System%20Account

    I’m using a MMD field, for example, of country terms: Africa > Algeria, Angola, etc. A user could tag to ‘Africa’ and/or any specific countries. In my filter, I want the page to have FilterField1=AfricaCountry&FilterValue1=Africa[OR]Algeria
    The practical situation is if some one applies the tag ‘Africa’ they mean every country below as well.
    Be grateful if anyone has any ideas.

  4. Martin says:

    Andrew, hi there.

    Do you know if their is any way to set a FilterValue if you don’t know the specific value that you want to filter and therefore can’t hardcode it into the URL?

    I have a list which is currently filtered on owners of tasks. So let’s say the user is looking at all tasks assigned to them. If they click on a link to go to NewForm.aspx and they then fill out a new task and return to the task list. The filter is lost and they can now see all tasks.

    How do I filter the task page on returning from the NewForm? I cant pre-set the FilterValue as the user name could be anything.

    Thanks Andrew,,
    Martin.

    1. Nicolas Rubin says:

      Hi Martin,

      Did you find solution for this ?
      I have exactly the same question, but no luck to solve it !
      Please let me now if you know something !!

      Nicolas

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s