Last active
February 11, 2016 17:03
-
-
Save vman/4701670 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 = []; | |
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); | |
//Properties to fetch from the User Profile | |
var profilePropertyNames = ["PreferredName","PictureURL"]; | |
//Domain\Username of the user (If you are on SharePoint Online) | |
var targetUser = "i:0#.f|membership|[email protected]"; | |
//If you are on On-Premise: | |
//var targetUser = domain\\username | |
//Create new instance of UserProfilePropertiesForUser | |
var userProfilePropertiesForUser = new SP.UserProfiles.UserProfilePropertiesForUser(clientContext, targetUser, profilePropertyNames); | |
userProfileProperties = peopleManager.getUserProfilePropertiesFor(userProfilePropertiesForUser); | |
//Execute the Query. | |
clientContext.load(userProfilePropertiesForUser); | |
clientContext.executeQueryAsync(onSuccess, onFail); | |
} | |
function onSuccess() { | |
var messageText = "\"Preffered Name\" property is " + userProfileProperties[0]; | |
messageText += "\"PictureURL\" property is " + userProfileProperties[1]; | |
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