SP.UserProfiles.UserProfilePropertiesForUser constructor (sp.userprofiles)

SharePoint 2013

Initializes a new instance of the UserProfilePropertiesForUser object.

Last modified: September 26, 2013

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

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

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.

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

Note 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") });
Show: