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.
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.
ReplyDeleteNow my client wants to see email addresses so I guess I replicate your post code for this. Good stuff and so quick to do.
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.
DeleteThanks for the file Ant, it worked like a dream!!
ReplyDeleteGood to hear it was a success.
DeleteThanks 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,
ReplyDelete...','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!
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
ReplyDeleteHi 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.
ReplyDeleteQuick update .. My search had broken. I reset the index and both my new custom attibutes are there
DeleteSo were you able to get office location working?
DeleteOnedrive link no longer works
DeleteI 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?
ReplyDeleteFirst 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
DeleteFor Mobile Phone use MobilePhone and not CellPhone.
Did office location work?
DeleteI added code for work email and office location but neither of them are showing up. Any suggestion?
DeleteThank you! Well done!
ReplyDeleteExcellent Post!! Thank you!
ReplyDeleteThanks! Also trying to display Office information in search results. Anyone who's able to do this?
ReplyDeleteTry OfficeNumber
ReplyDeleteThank you! It was very helpful.
ReplyDeleteI 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.
Thank you for this, easy to follow, and it worked! Thanks
ReplyDeleteI need to add "Browse in organizational chart" link, which is OOB feature in SP 2010 search, did one try this? Thank You
ReplyDeleteFind how to show user Birthday:
ReplyDelete1.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);
Thanks for adding this Sergey.
DeleteExcellent Post.
ReplyDeleteManaged 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
Thank you. Didn't take me to long to post this information but has proved very useful to all.
DeleteThank you so much! Worked liked a charm!
ReplyDeleteHappy to help.
DeleteHi,
ReplyDeletethanks 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 :-(
have it all working and behaving correctly now - many thanks for your blog!
DeleteGreat that its working and happy to help.
DeleteFixed it .. Checked in the File, did not publish.
DeleteOnce published - everyone sees the change..
Great BLOG Anthony
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?
ReplyDeleteIf 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.
DeleteHopefully that will help.
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.
DeleteMe neither :(
DeleteThanks for this! Downloaded your template and it worked! So helpful. Thanks for Sharing!
ReplyDeleteGreat. Hopefully saved you some time.
DeleteAnyone know what the code would be for adding the Company field from AD would be?
ReplyDeleteIt 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.
DeleteHI 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?
ReplyDeleteGreat blog. Works like a charm
ReplyDeleteVery helpful. How can I get AD Title field to display
ReplyDeleteGreat article. Thanks a lot
ReplyDeleteReally helpful, exactly what I was looking for.
ReplyDeleteIt 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?
ReplyDeleteHi 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 ?
ReplyDeleteThanks again,
Khushi
Very good article. This is just what we have been trying to figure out for a while now. Really appreciate the information.
ReplyDeleteIf 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
ReplyDeleteWorks 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.
ReplyDeleteThank you! It was very helpful.
ReplyDeleteI 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.
This worked great! Thanks!
ReplyDeleteAmazing article and thanks for sharing your file - worked a treat!
ReplyDeleteThis is great article. Is there any way i can show office location too?
ReplyDeletefile link doesn't work.
ReplyDeleteHi
ReplyDeleteI 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)