We are have sync the SP with AD using Active Directory Import for SharePoint 2013.
All the users have been picked up into the Manage User Profiles and new user properties have been added to the profiles.
Is it possible to query this profiles and fetch the properties for loggedin user?
How to do this in:-
JavaScript object model? (say on masterpage)
Server Object Model? ( say usercontrol on master page)
I tried foll. JS code:-
<script>
var personProperties;
// Ensure that the SP.UserProfiles.js file is loaded before the custom code runs.
SP.SOD.executeOrDelayUntilScriptLoaded(getUserProperties, 'SP.UserProfiles.js');
function getUserProperties() {
// Replace the placeholder value with the target user's credentials.
var targetUser = "mydomain\nachiket";
// Get the current client context and PeopleManager instance.
var clientContext = new SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
// Get user properties for the target user.
// To get the PersonProperties object for the current user, use the
// getMyProperties method.
personProperties = peopleManager.getPropertiesFor(targetUser);
// Load the PersonProperties object and send the request.
clientContext.load(personProperties);
clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);
}
// This function runs if the executeQueryAsync call succeeds.
function onRequestSuccess() {
alert('success');
alert(personProperties.get_displayName());
}
// This function runs if the executeQueryAsync call fails.
function onRequestFail(sender, args) {
alert(args.get_message());
}
</script>
But it doesnt execute the alert(personProperties.get_displayName());