I'm trying to get a custom user profile property, but I only get that the property is undefined.
What I'm trying to do is to get a custom user profile property, without having to loop trough the arrays of properties.
ex from microsoft .. http://ift.tt/1CmeYXc
var userProfileProperties;
// 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 = "awesome\administrator";
// Get the current client context and PeopleManager instance.
var clientContext = new SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
// Specify the properties to retrieve and target user for the
// UserProfilePropertiesForUser object.
var profilePropertyNames = ["PolicyAccept"];
var userProfilePropertiesForUser =
new SP.UserProfiles.UserProfilePropertiesForUser(
clientContext,
targetUser,
profilePropertyNames);
// Get user profile properties for the target user.
// To get the value for only one user profile property, use the
// getUserProfilePropertyFor method.
userProfileProperties = peopleManager.getUserProfilePropertiesFor(
userProfilePropertiesForUser);
// Load the UserProfilePropertiesForUser object and send the request.
clientContext.load(userProfilePropertiesForUser);
clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);
}
// This function runs if the executeQueryAsync call succeeds.
function onRequestSuccess() {
var messageText = "PolicyAccept property is "
+ userProfileProperties[0];
$('#MiddleLeftCell').prepend("<h1>" +messageText +"</h1>");
}
// This function runs if the executeQueryAsync call fails.
function onRequestFail(sender, args) {
$('#MiddleLeftCell').prepend("<h1>Error: " + args.get_message());
}
I've got this to work, but not without having to loop trough the whole array of properties. ex:
data.d.UserProfileProperties.results.filter(function (a, b) { return a.Key == name; })[0].Value;
Every property got a key so my other question is .. isn't there a way to have a direct lookup on a custom property?
Yes I've checked if the property is there and it's visible.
0 commentaires:
Enregistrer un commentaire