SharePoint Nirvana | Javascript

Add Search for Current Document Set

by JamieMcAllister 4. March 2015 10:14
  Document Sets were first introduced in SharePoint 2010 and are an excellent way to organize content. I've gained many enthusiastic users of Doc Sets, but there is one feature they often ask for - the ability to search inside a particular Document Set. The issue is that Document Sets can easily end up with tens or hundreds of documents in them, but the default search scope in SharePoint is usually going to search the whole site. With this in mind I devised a solution to allow my users to search just in the Document Set they're currently looking at. Wouldn't it be nice to allow users to search inside the current Document Set like this? It just takes a few minutes to put this together! (I've documented here for SharePoint 2010, but this also works for 2013 and Office 365 with a minor tweak detailed below)   One very nice feature of Document Sets is that they have a 'Homepage' that you can edit. This allows you to change the look and feel, including adding extra web parts and through use of the Content Editor Web Part add Script. This thinking led me to my solution... Search results webparts in SharePoint are driven by querystring parameters in the url of the page. I therefore realized that if I added a Core Search Results webpart to the Document Set homepage, and manipulated the URL with the users search term and the Document Set address then I could show Document Set specific Search results right there in the Document Set page. The concept is illustrated below. I need to take the url of the Doc Set, and add two querystring parameters; k for the search term and u for the container I wanted to search. (This is Microsoft's naming convention, not mine!)     To achieve the above I first need to change the Doc Set Homepage for my library. Go to library settings and click the Document Set Content Type. (This is assuming you've already added that!)     In the next page click Document Set Settings     In that next page you'll see an option to edit the Doc Set Welcome Page.     Now you see the default template for the welcome page     This is what that same page looks like when you click edit. The various web part zones are visible;     Upload the Javascript file (SearchAndFilter.js) I've attached at the end of the article to your local Assets Library. We're going to reference that file in a Content Editor Web Part (CEWP). Or you could take the text from that javascript file and paste into the HTML view of the CEWP, but that's not good practise. Now we add a CEWP to the page as shown;     In the Web Part settings, set the content link to be the javascript file you just uploaded to the Assets Library;     Next add a Search Core Results web part to the same web part zone;     Your page now looks like this;     Your users now see a Search box when they're viewing Document Sets. Entering a Search Term and clicking they see results from just that Document Set as below. This is better than before but the results are kind of ugly.     To change the look of the Search results to be friendlier, edit page again and go into the Search Core Results web part settings. Expand Display Properties, and click the XSL Editor button. (You may need to untick the 'Use Location Visualization' box to ungrey the button). In the editor that pops open, delete the text and paste in the contents of my SearchStyling.xsl file, also at the bottom of this article. Click OK and save your changes.     Your search results should now look fairly like a normal List View. Sorting and filtering is possible on the search columns, and the description field which is sometimes verbose can be expanded or not. The XSL I've provided can be tweaked to display different columns (there's a lot of properties in search results that aren't shown by default) including your own custom columns.     The files you need to make this work are below;   SearchAndFilter.js (3.60 kb) [SP2010] SearchStyling.xsl (10.91 kb) [SP2010] SearchAndFilterO365.js (3.60 kb) [SP2013 or Office 365]   If you need this for Office 365 or SharePoint 2013 instead, there's a one line tweak needed to the javascript. The Search Results webpart in that version puts it's 'search results not found' text in a different bit of the page. (Also you'll style your Search Results with Display Templates instead, which is off topic here.)   Happy SharePointing!


Document Management | Javascript | Office 365 | sharepoint 2010 | SharePoint 2013 | SharePoint Online

Hide Unwanted Fields On Calendar Form

by JamieMcAllister 22. March 2013 21:14
In a SharePoint Calendar the new item form has a bunch of fields that people don't always want to display. It's much harder to hide those fields than you might think, and here I detail how to do it. [More]


Javascript | sharepoint 2010

Webinar Materials

by JamieMcAllister 14. November 2012 19:09
Here is the supporting materials for the End User Solutions webinar. :) All resources and links to videos included. [More]

Tags: ,

End User | Infopath | Javascript | Sharepoint | sharepoint 2010 | SharePoint Designer | Webinar

Create Expandable Regions in MOSS Publishing Pages

by JamieMcAllister 8. July 2008 18:11
When there is a lot of text on a MOSS Publishing page it can spoil the presentation. This technique allows Publishing Page text to sit in regions that can be expanded and contracted by a reader. A custom button on the HTML editing toolbar makes it easy for content authors to add this feature. [More]

Tags: , ,

CMS | Javascript | WCM

Disclaimer: The software, source code and guidance on this website is provided "AS IS"
with no warranties of any kind. The entire risk arising out of the use or
performance of the software and source code is with you.

Any views expressed in this blog are those of the individual and may not necessarily reflect the views of any organization the individual may be affiliated with.