I'm trying to get the user properties of the current user using javascript.

In C# i can easily do it using event receivers on itemadding. However i want to use javascript in order to get the user properties and it doesn't seem to work. I keep getting errors.

Here is the code :

 function getCurrentUserInformation() {
    var context = new SP.ClientContext.get_current();

    var currentUser = context.get_web().get_currentUser();

    var peopleManager = new SP.UserProfiles.PeopleManager(context);

    var userProperties = ["InitialLeaveDays", "LeaveDays"];

    var userProfilePropertiesForUser = new UserProfilePropertiesForUser(context, currentUser, userProperties);


    context.executeQueryAsync(onRequestSuccess, onRequestFail);


I'm getting error on peopleManager = new SP.UserProfiles.PeopleManager(context); stating that can't get of undefined or null . Don't know what is wrong .

Any ideas?


1 Answer 1


You are not passing the correct user information. You need to pass the actual user login name. Also, you need to wait for the SP.UserProfile.js to be loaded before you execute your getMyProperties function.

Add/Ensure the below references in your sharepoint hosted app page:

<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.UserProfiles.js"></script>

Try the below code:

function getUserProperties() {
    var userProfileProperties;

    var clientContext = new SP.ClientContext.get_current();
    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);

    var currentUser = clientContext.get_web().get_currentUser();

        var loginName = currentUser.get_loginName();

        var profilePropertyNames = ["InitialLeaveDays", "LeaveDays"];
        var userProfilePropertiesForUser = 
            new SP.UserProfiles.UserProfilePropertiesForUser(

        userProfileProperties = peopleManager.getUserProfilePropertiesFor(userProfilePropertiesForUser);

            console.log("initial leave days :" + userProfileProperties[0]);
            console.log("leave days :" + userProfileProperties[1]);
        }, function(sender, args){

    },function(sender, args){

Also, ensure that your sharepoint hosted app has permission to read user profiles as below in your appmanifest.xml file:

enter image description here

  • Thanks for the reply . However the command SP.SOD.executeFunc won't execute my function . The breakpoint never hits my function.
    – shak
    Commented Oct 11, 2017 at 7:05
  • Please check the updated answer Commented Oct 11, 2017 at 7:15
  • Thanks a lot ! It worked! Much appreciate it for your help
    – shak
    Commented Oct 11, 2017 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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