// Ensure that the SP.UserProfiles.js file is loaded before the custom code runs.
var userProfileProperties;
SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function() {
// Make sure PeopleManager is available
SP.SOD.executeFunc('userprofile', 'SP.UserProfiles.PeopleManager', function() {
debugger;
// get the target users domain name and account name.
var targetUser = "i:0#.f|membership|inspiredata@gbtmarketingreview.onmicrosoft.com";
// Get the current client context.
var clientContext = new SP.ClientContext.get_current();
//Get PeopleManager Instance
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
// Get the properties to retrieve
var profilePropertyNames = ["AccountName", "FirstName","LastName","Assistant", "Office","Personal site","WorkPhone", "Mobilephone","CellPhone","Fax","Department" ];
var userProfilePropertiesForUser = new SP.UserProfiles.UserProfilePropertiesForUser(
clientContext,
targetUser,
profilePropertyNames);
// Get user profile properties for the target user
userProfileProperties =peopleManager.getUserProfilePropertiesFor(userProfilePropertiesForUser);
// Load the UserProfilePropertiesForUser object.
clientContext.load(userProfilePropertiesForUser)
//Execute the Query
clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);
});
});
// This function runs if the executeQueryAsync call succeeds.
function onRequestSuccess() {
debugger;
var messageText = "\" AccountName \" property is "
+ userProfileProperties[0];
messageText += "
\" FirstName \" property is "
+ userProfileProperties[1];
messageText += "
\" LastName \" property is "
+ userProfileProperties[2];
messageText += "
\" Assistant \" property is "
+ userProfileProperties[3];
messageText += "
\" Office \" property is "
+ userProfileProperties[4];
messageText += "
\" Personal site \" property is "
+ userProfileProperties[5];
messageText += "
\" HomePhone \" property is "
+ userProfileProperties[6];
messageText += "
\" Mobilephone \" property is "
+ userProfileProperties[7];
messageText += "
\" CellPhone \" property is "
+ userProfileProperties[8];
messageText += "
\" Fax \" property is "
+ userProfileProperties[9];
messageText += "
\" Department \" property is "
+ userProfileProperties[10];
alert("WorkPhone"+userProfileProperties[6])
$get("Display").innerHTML = messageText;
}
// This function runs if the executeQueryAsync call fails.
function onRequestFail(sender, args) {
debugger;
$get("Display").innerHTML = "Error: " + args.get_message();
}