Wednesday, July 2, 2014

SharePoint 2013: Add user profile properties to People search results

By default, People search results in SharePoint 2013 only shows the Job Title and Department user properties. You can add additional user properties using a custom Display Template by following these steps.

1. On the Search Center site, go to Site Settings, Master pages and page layouts, Display Templates, and Search. Download a copy of the Item_Person.html file to your desktop, and open the file in your favorite editor. In the mso:managedpropertymapping section, add your user properties in the same format as the existing ones. For example, the Mobile Phone user property would be:

'MobilePhone':'MobilePhone'

Be sure to separate all newly added user properties with a comma.

2. In the variable declarations section, add your additional user properties in the same format as the existing ones. For example, Mobile Phone would be:


3. In the section below the variable declarations section, add each additional user property's DIV content in the same format as the existing ones. For example, Mobile Phone would be:


Be sure to add each user property in the appropriate order in this section. So, if you want Mobile Phone to be located after the Work Phone property in People search results, add the Mobile Phone DIV content directly after the Work Phone DIV content.

4. Save and rename the the file to to something specific to your organization, such as Item_Person_Contoso.html.

5. Upload the file to the same location where you initially copied the file (Search Center site, Site Settings, Master pages and page layouts, Display Templates, and Search). Be sure to check in and publish a major version of the file.

6. Edit your peopleresults.aspx page, and then edit the People Search Core Results web part. Expand Display Templates, select Use a single template to display items, and then select your custom Display Template. Save the web part. Check in the peopleresults.aspx page and publish a major version.

Test People search results and ensure the properties are there. All done.

A few notes:

If some of the user properties don't show in the search results, you may have to tweak them a little. In particular, I have noticed the following:

Email = WorkEmail
Mobile Phone = MobilePhone
Office = OfficeNumber

To get the email address to show as a link, add the anchor tag to the DIV content as shown in the example below:

5 comments:

  1. Hi Thanks for a great post.. I have a problem with the mobile phone.. When debugging it in IE I can see that it's undefined.. Do you have an idea why it cannot show?

    ReplyDelete
  2. Same problem here.
    "has_mPhone" is undefined (CoreRender: ~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Person_MyCompany.js)
    Any idea how to fix that?

    ReplyDelete
  3. Hi Guys ..same problem..did you find a solution

    ReplyDelete
  4. I guess I'm late, but the reason for the undefined values are that you cannot modify an OOB Result Type, so you need to copy an existing one (http://YourSiteURL/_layouts/15/manageresulttypes.aspx?level=sitecol) and then refresh it after all your modifications. In this case, we need to copy the "Person" Result Type, creating a new one "Person 2", for instance. Then refresh the Result Type by PowerShell:

    $ssa = Get-SPEnterpriseSearchServiceApplication
    $tenantOwner = Get-SPEnterpriseSearchOwner -Level SPWeb -SPWeb "https://YourSearchCenterURL"
    Get-SPEnterpriseSearchResultItemType -Owner $tenantOwner -SearchApplication $ssa
    $ResultType = Get-SPEnterpriseSearchResultItemType -SearchApplication $ssa -Owner $tenantOwner | where-object { $_.Name -eq "Person 2" }
    $ssa.UpdateResultItemType($ResultType)

    Main source: https://social.msdn.microsoft.com/Forums/office/en-US/3150b424-6d1c-448c-8ca5-b79e5d8c5f40/property-sync-message-missing-in-result-types?forum=appsforsharepoint

    ReplyDelete

  5. If some of the user properties don't show in the search results, you may have to tweak them a little.


    online baccarat
    สูตรบาคาร่า
    baccarat

    ReplyDelete