Useful JavaScript Function – Refreshing a page with parameters for use with Query String Filter Web Parts in #SP2010 #SharePoint #ProjectServer #PS2010 #in
In my current project I have the need to determine the current users personal preferences based on favourites stored in a list.
These personal preferences then drive various web parts on the page.
Using this the Enterprise Edition of SharePoint Server 2010 makes this very easy with the use of the Query String Filter Web Part and various other web parts that support connections including:
- Reporting Services Web Part
- Excel Services Web Part
- List Web Parts
- etc…
Using the combination of parameters and the above web parts it makes it a lot easier to create dashboard pages that are specific to a users:
- Preferences
- Job Role
- Department
- etc…
Now in most of my projects, I have found that dashboard pages tend to be buried under a 2nd or 3rd level of navigation, which makes it very easy to create links with parameters already in them.
However, in this case, I have to create various dashboard pages at the root of the site, whilst using standard SharePoint Publishing Navigation (Global Navigation). The parameters being passed are user selectable based on favourites stored in a list.
Given that the SharePoint Site Map Provider doesn’t know about this random favourites list I have created, I need to improvise to ensure that the end user is presented with dashboard pages personalised to them, as soon as they hit the root site URL.
Code Example:
Essentially the following happens:
- The page load to a certain point
- We determine if we have the query string parameter(s) we are looking for
- If we don’t, we stop the page from rendering using document.execCommand(“stop”)
- Go get our require parameter(s)
- Determine if any previous parameters existed on the page currently (to make the code more generic)
- Reload the page with the new parameter(s)
If you find any unwanted page flashing before the page reload, use JavaScript to set style=”display: none;” on the main content <div> on the v4.master – Master Page, if the parameter doesn’t exist.
Although this is certainly one method of achieving my goal and seems to currently fit my clients requirements, I would certainly be interested to hear from others on how to achieve my goal without drastically changing standard SharePoint components.