One of the clients I have been working with recently wanted to extend the normal people search in SharePoint with the ability to track staff who are First Aiders. Exactly the same concept can be applied to other roles such as Fire Wardens, JPs and Health & Safety Representatives.
User Profile Service
The first thing we need to do is add a field to our User Profile properties. Go to Central Administration -> Manage Service Applications -> User Profile Service -> Manage User Properties and add a new property. I called mine FirstAid and made it a Boolean field, then allowed it to be edited by the user and shared with everyone.
Good start. Now users will be able to set the checkbox themselves to indicate that they are first aid qualified.
Before we go any further, run a full crawl to make sure the search service knows about our new field.
Then head to Central Administration -> Manage Service Applications -> Search Service -> Metadata Properties and create a New Managed Property. To keep it consistent I called this FirstAid again, set it to Yes/No (to match the Boolean) and then Add Mapping to the People:FirstAid field we have just created.
Make sure you tick the last checkbox to add the managed property to custom results.
Another full crawl should now make sure the property is ready to be used in our search results.
Now we need to add our field to the people search results page. I decided to display this as an icon so I added a green cross image to a library to represent my first aiders.
Navigate to your people search page, by default this will be peopleresults.aspx in your search centre. Edit the page through the browser and edit the People Search Core Results web part.
There are a couple of things we need to change here. Firstly, we need to include the field in the results which are returned. Under the Display Properties section we need to edit the Fetched Properties – you may need to un-tick Use Location Visualisation – then add in <Column Name=”FirstAid” /> – the order is not important.
Finally we need to display our icon for those users who have indicated that they are First Aiders. You have a few options how to achieve this but I am going to suggest what I consider to be the most flexible.
Click on XSL Editor. . . and you will be presented with an extended text box containing the XSLT which is used to present the default people search. Press CTRL-A and then CTRL-C to select it all and copy it. In SharePoint Designer 2010 (or your preferred XSLT editor) create a new XML file and rename to PeopleSearch.xsl. Edit this file and CTRL-V to paste in the copied XSLT.
I am not going to explain this file in detail – perhaps that is another blog post – but for now search for:
Insert the following just before it:
<xsl:if test="firstaid = 'True'"> <img src="/imagelibrary/firstaid.png" title="First Aider" alt="First Aider" style="cursor:pointer" onclick="location.search='?k=FirstAid:1'" > </xsl:if>
This does two things:
- Displays the chosen image if the first aid checkbox is ticked in the user profile
- Refreshes the page to show all first aiders if a user clicks on the icon
Save the XSLT file and grab the path to it. Return to your people results page and under the Miscellaneous section paste the path into the XSL Link. This will override anything in the XSL Editor and means that in future you can make further modifications without editing the page itself. It can also be reused on multiple pages if needed.
As a nice addition, you may also like to add the image as a fixed icon on the search page so users can find first aiders simply by clicking on it.
Note that an incremental crawl will need to run before any changes users make to their profiles appear in search results. I would definitely recommend communicating this to the user population as it will avoid confusion and repeated queries.