Last active
December 12, 2015 02:48
-
-
Save vman/4701756 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
$(document).ready(function(){ | |
// Ensure that the SP.UserProfiles.js file is loaded before the custom code runs. | |
SP.SOD.executeOrDelayUntilScriptLoaded(loadUserData, 'SP.UserProfiles.js'); | |
}); | |
var userProfileProperties = []; | |
//Array containing domain\usernames of multiple users. You can get the usersnames any way you want. | |
var targerUsers = ["i:0#.f|membership|vardhaman@yoursite.onmicrosoft.com","i:0#.f|membership|demouser1@yoursite.onmicrosoft.com"]; | |
//If you are on On-Premise: | |
//var targerUsers = ["domain\\username","domain\\demouser1"]; | |
function loadUserData(){ | |
//Get Current Context | |
var clientContext = new SP.ClientContext.get_current(); | |
//Get Instance of People Manager Class | |
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext); | |
//Property to fetch from the User Profile | |
var propertyName = "PreferredName"; | |
for(var i=0;i<targerUsers.length;i++){ | |
//Create new instance of UserProfileProperty | |
userProfileProperties[i] = peopleManager.getUserProfilePropertyFor(targerUsers[i], propertyName); | |
} | |
//Execute the Query. (No load method necessary) | |
clientContext.executeQueryAsync(onSuccess, onFail); | |
} | |
function onSuccess() { | |
var messageText = ""; | |
for(var i=0;i<userProfileProperties.length;i++){ | |
messageText += "\"Preffered Name\" property is " + userProfileProperties[i].get_value(); | |
} | |
alert(messageText); | |
} | |
function onFail(sender, args) { | |
alert("Error: " + args.get_message()); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment