Skip to main content

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.

Comments

Popular posts from this blog

How to partition or split DataTable in C#?

Today we will discuss how we can divide or split a very large data table into fixed size of chunks? Scenario: Suppose there is a data table which has 1000 Rows. When you perform for each loop on data table and read each row at that time it will take too much time. If we devide 1000 Rows datatable into 10 fixed sizes (e.g. 100 Rows) datatable, It will take less time. Let's check how to achieve it. Here is a code. private static List<DataTable> SplitTable(DataTable originalTable, int batchSize) { List<DataTable> tables = new List<DataTable>(); int i = 0; int j = 1; DataTable newDt = originalTable.Clone(); newDt.TableName = "Table_" + j; newDt.Clear(); foreach (DataRow row in originalTable.Rows) { DataRow newRow = newDt.NewRow(); newRow.ItemArray = row.ItemArray; newDt.Rows.Add(newRow); i++; if (i == batchSize) ...

How To Lock Objects In Power BI

Overview Sometimes, there is a situation where when we open a report and click on any visual it accidentally nudges a chart a little bit to the right or left. Sometimes, by mistake when viewing a report, the arrangement of visuals scatters a little bit. Microsoft rolls out one new amazing feature to resolve this issue, that is, Lock Objects in Power BI. Advantages of using this feature When our purpose is to only view a report, this feature is a boon for us. Visualization’s position is not changed. Saves a lot of the developer's time to resolve the position related issues. Note   -  This feature is not saved with the report. So, every time you open a report, you need to enable this feature. Now, let’s understand this feature in a brief manner. To understand this, I will first show you one report in which I have not enabled “Lock Objects” feature. Step 1 The below screenshot shows my report which doesn’t have the enabled Lock Objects feature. ...

Use SharePoint Online List As A Data Source In Power BI

Introduction In this article, we will check how we can use SharePoint List as a data source in Microsoft Power BI. Please follow the below steps to establish the connection of SharePoint Online list with Power BI.  Step 1 Open Power BI Desktop > Get Data > Click More.   Step 2 Search for SharePoint > SharePoint Online List.   Step 3 Enter the URL of your SharePoint site.   Step 4 Click on Organizational account > Sign In.   Step 5 It will open the screen of Office 365 Login > Enter Credentials.   Step 6 Click on Connect.   Step 7 It will show all the lists available in the SharePoint - lists are on the left corner and their preview is on the right. Select all the lists which you want to use directly in the Power BI. Click on Load.   Step 8 It will load all the lists. Expand "Fields" column to view all the fields shown in the SharePoint List.   We can also view all the...