0
        var clientContext = 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.
    MyProperties = peopleManager.getMyProperties();

    // Load the PersonProperties object and send the request.
    clientContext.load(MyProperties);
    clientContext.executeQueryAsync(getMyNewsChoicesSuccess, getMyNewsChoicesFail);
    },

    getMyNewsChoicesSuccess = function () {
        //get the news choice by actually fieldname
        var MyChoices = (MyProperties.get_userProfileProperties());
        $('#NBStest').text(MyChoices);

    },

My code here works however it returns [object object] when I add JSON.stringify it returns

{"UserProfile_GUID":"134ebf5f-4b97-464b-8362-a1ea699df676","SID":"S-1-5-21-516259181-3605073475-84029850-3763","ADGuid":"","AccountName":"main\\dah","FirstName":"Dave","SPS-PhoneticFirstName":"","LastName":"Horsley","SPS-PhoneticLastName":"","PreferredName":"Dave Horsley","SPS-PhoneticDisplayName":"","WorkPhone":"","Department":"Developers"}

If I then did JSON.parse it returns [object object] again. just need away of getting whats in my array/key value pairs

1

SP.UserProfiles.PersonProperties.userProfileProperties property returns an a dictionary of property name keys and their string values.

In JavaScript you could use the following syntax to access value in a dictionary:

myProperties.get_userProfileProperties().UserName

or

myProperties.get_userProfileProperties()['UserName'] 

Example

var context = SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(context);
var myProperties = peopleManager.getMyProperties();
context.load(myProperties);
context.executeQueryAsync(
   function() { 
      console.log('User Name:' + myProperties.get_userProfileProperties().UserName);
   },
    function(sender, args) {
       console.log(args.get_message());
    }
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.