Create Custom People Search Page With Phone Number Attribute In SharePoint Online

We have a requirement from one of our clients. They want to modify the “peopleresults.aspx” page which is the default People Search Page provided by SharePoint OOTB.

SharePoint OOTB People Search page provides the following properties.

  • Name
  • Title
  • Department
  • About Me

Below is a screenshot of OOTB People Search result which will sync the above four properties from SharePoint User Profiles.



We want to show Phone Number with People Search. For that, make sure that Phone number is already synced from AD to SharePoint User Profiles. I assume that we have synced Phone Number already. First, we will modify OOTB template of People Search. For that, first, go to Search Center Site.

Ex - https://abc.sharepoint.com/search

1. Go to Site Setting > Web Designer Gallery >Master Page and Page Layout.

 

2. Click on "Display Templates".

 

3. Click on "Search".

 

4. Download a copy of “ItemPerson.html”.

 

5. Now, we will modify the code and rename the file.

A. Change Title and modify code in <mso:ManagedPropertyMapping>.

 
Code 
  1. <title>Custom People Item Phone</title>  
  1. <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','WorkId':'WorkId','YomiDisplayName':'YomiDisplayName','WorkPhone':'WorkPhone','PhoneExtension':'PhoneExtension'</mso:ManagedPropertyMapping>  

B. Add the following code in <div id="Item_Person">

 
 
Code
  1. var has_wphone = !$isEmptyString(ctx.CurrentItem.WorkPhone);  
  2. var has_ext = !$isEmptyString(ctx.CurrentItem.PhoneExtension);  

C. Add the following code in <div id="ContactInfo">

 

Code
  1. <!--#_ if(has_wphone == true) { _#-->  
  2.    
  3. <div id="WorkPhone">  
  4. <!--#_ var encodedwphone = $htmlEncode(ctx.CurrentItem.WorkPhone); var displaywphone = Srch.U.getSingleHHXMLNodeValue(hhProps, "WorkPhone"); if ($isEmptyString(displaywphone)) { displaywphone = encodedwphone } _#-->  
  5.    
  6. <div id="WorkPhoneValue" class="ms-srch-ellipsis" title="_#= encodedwphone =#_">Phone: _#= displaywphone =#_ </div>  
  7.    
  8. </div>  
  9.    
  10. <!--#_ } _#-->  
  11. <!--#_ if(has_ext == true) { _#-->  
  12.    
  13. <div id="PhoneExtension">  
  14. <!--#_ var encodedext = $htmlEncode(ctx.CurrentItem.PhoneExtension); var displayext = Srch.U.getSingleHHXMLNodeValue(hhProps, "PhoneExtension"); if ($isEmptyString(displayext)) { displayext = encodedext } _#-->  
  15.    
  16.  <div id="PhoneExtensionValue" class="ms-srch-ellipsis" title="_#= encodedext =#_"> _#= displayext =#_ </div>  
  17.       
  18. </div>  
  19.       
  20. <!--#_ } _#--> 

6. Now, upload a modified file in Master Page Gallery>Display Template>Search Folder > Upload.

 
 

7. It will create a .js file automatically. Don’t forget to publish the page.

 

8. Now, we will create our custom people search page. 

9. Go to Search center site > Settings 

Ex: https://domain-name.sharepoint.com/search


10. Look and Feel > Page Layouts and site Templates.
 
 

11. Go to Site Contents > Pages Library.

 

12. Files> New Document >Article Page.

 

13. Give a name for the Page and click OK.

 

14. Edit a page that we have created > Edit People Search Core Web part

 

15. Select “Use a single item from a display template” > Select Uploaded Template > Save

 

16. Publish Page and check changes

17. Now you will be able to see Phone Number in People Search.

Conclusion

This is how we can add phone number attribute with search page and also how we can create our own custom Page.