Share via


SP.UserProfiles.UserProfilePropertiesForUser constructor (sp.userprofiles)

Initializes a new instance of the UserProfilePropertiesForUser object.

Applies to: apps for SharePoint | Office 365 | SharePoint Foundation 2013 | SharePoint Server 2013

var object = new SP.UserProfiles.UserProfilePropertiesForUser(context, accountName, propertyNames)

Parameters

  • context
    SP.ClientContext
    The client context to use.

  • accountName
    String
    The account name of the specified user.

  • propertyNames
    String[]
    The names of the target user profile properties.

Example

The following code example shows how to initialize a new instance of the UserProfilePropertiesForUser object.

Note

Replace the targetUser placeholder value before you run the code.

var targetUser = "domainName\\userName";

// Create the client context and get the PeopleManager instance.
var clientContext = new SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);

// Get user profile properties for the target user.
// Specify the properties to retrieve and create the UserProfilePropertiesForUser object.
// Then get the requested properties by using the getUserProfilePropertiesFor method.
var profilePropertyNames = ["PreferredName", "Department", "Title"];
var userProfilePropertiesForUser = new SP.UserProfiles.UserProfilePropertiesForUser(
    clientContext,
    targetUser,
    profilePropertyNames);
var userProfileProps = peopleManager.getUserProfilePropertiesFor(userProfilePropertiesForUser);

clientContext.load(userProfilePropertiesForUser);
clientContext.executeQueryAsync(
    function () { alert(userProfileProps[0] + " works in " + userProfileProps[1] + " as a " + userProfileProps[2]); },
    function () { alert("Failure") });

See also

Other resources

UserProfilePropertiesForUser

How to: Retrieve user profile properties by using the JavaScript object model in SharePoint 2013