sharepointsharepoint-2013javascript-objectssharepoint-jsom

SharePoint userProfileProperties JSOM (JavaScript Object Model)


I am tryin to get some info from PeopleManager.getMyProperties() function. I get the object,some values are null.when i check it from User Profile from Management,I can see the value. How can i fix this one ?

There is my working code to get object.
Note : I want to access Custom Property from User Profile which I created before. I can see the property in the object but value is not coming.

Thank You All..

  $(document).ready(function(){         
    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);

    //Get properties of the current user
    userProfileProperties = peopleManager.getMyProperties();

    clientContext.load(userProfileProperties);

    //Execute the Query.
    clientContext.executeQueryAsync(onSuccess, onFail);

  }

  function onSuccess() {        
       console.log(userProfileProperties)    
  }

  function onFail(sender, args) {
       console.log("Error: " + args.get_message());
  } 

Solution

  • I forget to write the solution,sorry for that one.

    I tried the code which written by @NaveenPrasath. It is giving a lot of fields but it didn't return "Custom Prop Field".

    Working code is shown below.

    function getUserProperties(targetUser) {
    
        var clientContext = new SP.ClientContext.get_current();
        var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
        personProperties = peopleManager.getPropertiesFor(targetUser);
        clientContext.load(personProperties);
        clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);
    }
    
    function onRequestSuccess() {
            var fullName = personProperties.get_userProfileProperties()['CustomPropField'];
    }