Friday 20 September 2013

Get Multiple User Properties in SharePoint 2013

var users=["domain\\kalpeshp", "domain\\sachinka", "domain\\nikhils"];

function GetUserProperties(clientContext, peopleManager, targetUser, profilePropertyNames){
 var userProfilePropertiesForUser = new SP.UserProfiles.UserProfilePropertiesForUser(
  clientContext,
  targetUser,
  profilePropertyNames);
 var userProfileProps = peopleManager.getUserProfilePropertiesFor(userProfilePropertiesForUser);

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


function GetAllUserProperties(){
 var targetUser = "domain\\kalpeshp";

 // 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"];

 for(var i=0; i<users.length;i++){
     GetUserProperties(clientContext, peopleManager, users[i], profilePropertyNames);
 }
}

Share This!


No comments:

Post a Comment

Translate

Total Pageviews

Powered By Blogger · Designed By Seo Blogger Templates