1
votes

When I was writing custom display template for SharePoint people search, I wanted to display the manager of the searched user. When I display the manager value returned from SharePoint people search, it displays as follows:

i:0#.f|membership|[email protected]

I want to show the display instead of the account name in my SharePoint display template. Let me know if this can be done either using JavaScript or just by doing some configurations on SharePoint user profile property change.

1

1 Answers

1
votes

This cannot be done using just configurations. You will need to query the User Profile Service and get the Display Name using the login name the search service returns.

For obtaining any property you can use something like this:

function getProfilePropertyValueFromLoginName(loginName, propertyName, success, error) {
            // Get the current client context and PeopleManager instance.
            var clientContext = new SP.ClientContext.get_current();
            var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);

            // Get user properties for the target user.
            // To get the PersonProperties object for the current user, use the
            // getMyProperties method.
            var personProperties = peopleManager.getPropertiesFor(loginName);

            // Load the PersonProperties object and send the request.
            clientContext.load(personProperties);
            clientContext.executeQueryAsync(
                function () {

                    if (success) {
                        success(loginName, personProperties.get_userProfileProperties()[propertyName]);
                    }
                }, function (sender, args) {
                    if (error) {
                        error(sender, args);
                    }
                });
        }

-Hope it helps