Monday 16 September 2013

People Search with Work Number in SharePoint 2013


A couple of times recently I have been asked about adding a work phone number to the people results page. 

 
In SharePoint 2010 this was achieved through editing the XML on the page but 2013 has a different approach.  With SharePoint 2013 we have the concept of display templates and to add a work number to the people results page we need to create a new display template which I will be covering in this blog.
To start with we need to take the existing people results display template and use this as a basis to create a new file.  This can be found in the Search site collection under ‘Site Settings’ – ‘Master Pages and Page Layouts’ then within this library we look for the Display Templates folder and then the Search sub folder.  Take a copy of ‘Item_Person.html’ which it easiest downloaded.
Now edit our copied file to then edit or add the following lines:-

<title>People Item with Work Phone</title>
<mso:ManagedPropertyMapping msdt:dt="string">'AboutMe':'AboutMe','AccountName':'AccountName','BaseOfficeLocation':'BaseOfficeLocation','Department':'Department','HitHighlightedProperties':'HitHighlightedProperties','Interests':'Interests','JobTitle':'JobTitle','LastModifiedTime':'LastModifiedTime','Memberships':'Memberships','PastProjects':'PastProjects','Path':'Path','PictureURL':'PictureURL','PreferredName':'PreferredName','Responsibilities':'Responsibilities','Schools':'Schools','ServiceApplicationID':'ServiceApplicationID','SipAddress':'SipAddress','Skills':'Skills','UserProfile_GUID':'UserProfile_GUID','WorkEmail':'WorkEmail','WorkPhone':'WorkPhone','WorkId':'WorkId','YomiDisplayName':'YomiDisplayName'</mso:ManagedPropertyMapping>

var has_wphone = !$isEmptyString(ctx.CurrentItem.WorkPhone);

<!--#_                                         if(has_wphone == true) {
_#-->
                                            <div id="WorkPhone">

<!--#_                                         var encodedwphone = $htmlEncode(ctx.CurrentItem.WorkPhone);

                                                var displaywphone = Srch.U.getSingleHHXMLNodeValue(hhProps, "WorkPhone");

                                               if ($isEmptyString(displaywphone)) { displaywphone = encodedwphone }

_#-->
                                                <div id="WorkPhoneValue" class="ms-srch-ellipsis" title="_#= encodedwphone =#_"> _#= displaywphone =#_ </div>
                                            </div>
<!--#_                                         }
_#-->

Once completed then save as a new name or to make things easier I have already created the file and it is available from my OneDrive.

Once the file has been edited then it needs uploading back in to the Master Pages library under the Display Templates folder and Search sub folder.  When this file is uploaded SharePoint 2013 will automatically generate a shadow file with a ‘.js’ file extension.

Finally we now need to edit our people search results page and point it to the new display template.  With the ‘peopleresults.aspx’ in an edit mode find the ‘People Search Core Results’ and edit the web part.



Change the Display Template option to ‘Use a single template to display items’ and choose our ‘People Item with Work Phone’ from the drop down list available. 

Save the web part properties and publish our people search results page.  Then run a new search for people and we should see the Work Number appear for each person.
 


This can be done for any of the user profile properties that we want to promote on to the Search results page.   Plus the approach can also be used for any of the other Search pages in our Search Centre.

55 comments:

  1. Excellent and very relevant post. I have a few comments I would like to share 1) You need the SharePoint Server Publishing feature enabled 2) You can access the Display Templates from the new Display Manager - map to a drive to make things easier. 3) I used both notepad++ and SharePoint Designer 2013 to make the changes. 4) You do need to make the changes in the correct locations so a bit of care is needed: my first attempt failed when I realised I put my <if in the wrong place doh! 5) note the conversion successful status message when it changes to .js) 5) Finally don't forget to publish to all all to see changes.

    Now my client wants to see email addresses so I guess I replicate your post code for this. Good stuff and so quick to do.

    ReplyDelete
    Replies
    1. Thanks for the additional information which is very helpful. Glad you found the post useful and it is a quick win for those who want to promote the phone number or additional information through people search.

      Delete
  2. Thanks for the file Ant, it worked like a dream!!

    ReplyDelete
  3. Thanks for this post, Everything is working fine, I'm able to show work phone and E-mail but also I need to show Office, I've been trying with all kind of combinations but none is working, I used BaseOfficeLocation, Office, physicalDeliveryOfficeName but still is not working, this is my code that I'm Using,

    ...','Office':'Office','YomiDisplayName':'YomiDisplayName'

    var has_Office = !$isEmptyString(ctx.CurrentItem.Office);


    div id="OfficeLocation"

    div id="OfficeLocationValue" class="ms-srch-ellipsis" title="_#= encodedOfficeLocation =#_" _#= displayOfficeLocation =#_



    Any advise ??

    Thanks!

    ReplyDelete
  4. Hi,I am trying show custom user profile properties in a display templates. But some reason managed mapped properties are not showing results in display template

    ReplyDelete
  5. Hi the person who is using office ... I have done this for my client as in Set-User $samAccountName -Office "10 Downing street" . You can't use location because this not part of the User class ( it is actually meant for the location of printers) .. Now as for the custom attributes. Can your confirm that these are appearing on the user's mysites either on the right hand site or in the Edit Details.. In my case they are in in AD but not appearing in SharePoint. I am thinking I won't both changing the display template until I can see that they are there.

    ReplyDelete
    Replies
    1. Quick update .. My search had broken. I reset the index and both my new custom attibutes are there

      Delete
    2. So were you able to get office location working?

      Delete
    3. Onedrive link no longer works

      Delete
  6. I am trying to get office and mobile phone to add. Tried to replicate the code with the new field names but had no luck . Any tips?

    ReplyDelete
    Replies
    1. First check if you can see those number under my site after adding them in AD? Else you will have to create a mapping for it and then run a full crawl. Once you have the numbers displayed in my site. You can edit the template

      For Mobile Phone use MobilePhone and not CellPhone.

      Delete
    2. Did office location work?

      Delete
    3. I added code for work email and office location but neither of them are showing up. Any suggestion?

      Delete
  7. Thank you! Well done!

    ReplyDelete
  8. Excellent Post!! Thank you!

    ReplyDelete
  9. Thanks! Also trying to display Office information in search results. Anyone who's able to do this?

    ReplyDelete
  10. Try OfficeNumber

    ReplyDelete
  11. Thank you! It was very helpful.
    I trying also to add birthday, but don't have any results.
    I try:
    'Birthday':'Birthday'
    var has_birthday = !$isEmptyString(ctx.CurrentItem.Birthday);

    Any suggestions?
    Thank you.

    ReplyDelete
  12. Thank you for this, easy to follow, and it worked! Thanks

    ReplyDelete
  13. I need to add "Browse in organizational chart" link, which is OOB feature in SP 2010 search, did one try this? Thank You

    ReplyDelete
  14. Find how to show user Birthday:
    1.You need in search schema map crawler property "SPS-Birthday" to manage property (for example "RefinableDate00")
    2. Wait until full crawl is done
    3. Operate with "RefinableDate00" in your search template file
    'RefinableDate00':'RefinableDate00'
    var has_birthday = !$isEmptyString(ctx.CurrentItem.RefinableDate00);

    ReplyDelete
  15. Excellent Post.
    Managed to add Work Email and phone in one go. Just took me 10 mins to do all the things. Thanks for saving me heaps of time.
    Cheers
    Daws

    ReplyDelete
    Replies
    1. Thank you. Didn't take me to long to post this information but has proved very useful to all.

      Delete
  16. Thank you so much! Worked liked a charm!

    ReplyDelete
  17. Hi,

    thanks for this - i followed through the guide on-premises sharepoint 2013 - however it only works for my admin user, my normal users get the wonderful "sorry something went wrong" error message.

    i tried with my own coded page and also downloaded a version from your onedrive - get the same result each time :-(

    ReplyDelete
    Replies
    1. have it all working and behaving correctly now - many thanks for your blog!

      Delete
    2. Great that its working and happy to help.

      Delete
    3. Fixed it .. Checked in the File, did not publish.
      Once published - everyone sees the change..

      Great BLOG Anthony

      Delete
  18. I can't get the last step to work. The template does not show up in the Item Display Template drop down on the peopleresults.aspx People Search Core Results web part in edit mode. I published the file, still no luck. Help?

    ReplyDelete
    Replies
    1. If it cant be seen as a display template when editing the web part then check it is in the Master Page gallery as a web template. You should see others in there and then check is generates an associated .js file. I have seen instances where this doesn't create the associated file straight away and last resort delete the file, wait and add it again with a unique name.

      Hopefully that will help.

      Delete
    2. Did this work? I am facing the same issue. I have published and approved the new display template. I have tried deleting it and adding it again under a differente name. I am not having any luck getting it to appear in the web part's "Display Template" Drop down option.

      Delete
    3. Me neither :(

      Delete
  19. Thanks for this! Downloaded your template and it worked! So helpful. Thanks for Sharing!

    ReplyDelete
  20. Anyone know what the code would be for adding the Company field from AD would be?

    ReplyDelete
    Replies
    1. It would be very similar to above but I believe instead of using the 'workphone' you would replace this with 'orgnames' as the Company field is an alias to this in the search centre. Haven't tried it so let us know how you get on.

      Delete
  21. HI i also had this requirement and achived this almost same way. The issue i identified (even in this post), with custom display or tweaked display template, people online status is not appearing. Any way to fix this?

    ReplyDelete
  22. Great blog. Works like a charm

    ReplyDelete
  23. Very helpful. How can I get AD Title field to display

    ReplyDelete
  24. Great article. Thanks a lot

    ReplyDelete
  25. Really helpful, exactly what I was looking for.

    ReplyDelete
  26. It was really helpful and got it working for the "People" tab. Now, how do I apply the same template to be used in the "Everything" tab?

    ReplyDelete
  27. Hi there - Thanks for posting such a informative article. Really Appreciate it. Quick Question - I did try to show Manager and Assistant's name but it is not displaying. Is it because they are of people type? I did try $htmlEncode(ctx.CurrentItem.Manager.FirstName); but it is not working. Any idea ?

    Thanks again,
    Khushi

    ReplyDelete
  28. Very good article. This is just what we have been trying to figure out for a while now. Really appreciate the information.

    ReplyDelete
  29. If somebody wants expert take on the main topic of blogging next I advise him/her to go to this site, continue the fussy job.SearchPeopleUSA

    ReplyDelete
  30. Works like a dream, thanks for putting the html out there for those of us who don't write a lot of code. Really made things easy.

    ReplyDelete
  31. Thank you! It was very helpful.
    I tried also to add home phone, but don't have any results.
    I tried:
    'RefinableString10':'RefinableString10'
    ...
    var has_hphone = !$isEmptyString(ctx.CurrentItem.RefinableString10);
    ...


    and in Crawled Properties RefinableString10 -> People:HomePhone

    What's wrong? Any suggestions?
    Thank you.

    ReplyDelete
  32. This worked great! Thanks!

    ReplyDelete
  33. Amazing article and thanks for sharing your file - worked a treat!

    ReplyDelete
  34. This is great article. Is there any way i can show office location too?

    ReplyDelete
  35. Hi
    I get this error when trying to follow the above steps. Can you please assist?
    'has_wphone' is undefined (CoreRender: ~sitecollection/_catalogs/masterpage/Display Templates/Search/PeopleItemWithWorkPhone.js)

    ReplyDelete