none
SCRIPT5022: Object reference not set to an instance of an object on server. The object is associated with method GetPropertiesFor. RRS feed

  • Question

  • I have successfully read some user profile properties for a target user, and I'm trying to display them, but when the code tries to retrieve one of the data fields using a method which appears to be valid, then I get the error shown above on this line of code:

       var prprtysStr = "MY PROPERTIES ARE:\n DISPLAY NAME("+myProperties.get_displayName()+")\n ACCOUNT NAME("+myProperties.get_accountName()+"),\n EMAIL("+myProperties.get_email()+"),\n TITLE("+myProperties.get_title()+") PICTURE-URL("+myProperties.get_pictureUrl()+").\n"

    The block of code that I'm trying to use to read and extract the data from userProfileProperties looks like this:

     function getUserProperties(slctdTmMmbr,slctdName)
     {  
      try
      {
       console.log("METHOD: 'getUserProperties' ENTERED.");
       
       var mnfctrdUserName = ConstructUserName(slctdTmMmbr,slctdName);
       var targetUser = "domainName\\"+mnfctrdUserName;
       var prprtsCntxt = new SP.ClientContext.get_current();
       var peopleManager = new SP.UserProfiles.PeopleManager(prprtsCntxt);
       
       alert("TARGET-USER=("+targetUser+").");
       
       var personProperties = peopleManager.getPropertiesFor(targetUser);
       
       prprtsCntxt.load(personProperties);   
       prprtsCntxt.executeQueryAsync(Function.createDelegate(this,function(){showPersonProperties(prprtsCntxt,personProperties);}), personPropertiesQueryFailed);
      }
      catch(excptn)
      {
       console.log("METHOD: 'getUserProperties' - Exception: '"+ excptn.name + "'  -  " + excptn.message);
       throw excptn;
      }
      finally
      {
       console.log("METHOD: 'getUserProperties' EXITED.");
      }
     }
     
     function showPersonProperties(prprtsCntxt,myProperties)
     {
      try
      {
       console.log("METHOD: 'showPersonProperties' ENTERED.");
       
       var prprtysStr = "MY PROPERTIES ARE:\n DISPLAY NAME("+myProperties.get_displayName()+")\n ACCOUNT NAME("+myProperties.get_accountName()+"),\n EMAIL("+myProperties.get_email()+"),\n TITLE("+myProperties.get_title()+") PICTURE-URL("+myProperties.get_pictureUrl()+").\n"
       
       
       //var prprtysStr2 = " DEPARTMENT("+myProperties.get_userProfileProperties()['Department']+"),\n CELL-PHONE("+myProperties.get_userProfileProperties()['CellPhone']+"),\n PREFERRED NAME("+myProperties.get_userProfileProperties['PreferredName']+"),\n FIRST NAME("+myProperties.get_userProfileProperties['FirstName']+"),\n SPS-BIRTHDAY("+myProperties.get_userProfileProperties['SPS-Birthday']+"),\n USER-NAME("+myProperties.get_userProfileProperties['UserName']+"),\n WORK-EMAIL("+myProperties.get_userProfileProperties['WorkEmail']+"),\n WORK-PHONE("+myProperties.get_userProfileProperties['WorkPhone']+"),\ MANAGER("+myProperties.get_userProfileProperties['Manager']+").";
       
       alert(prprtysStr);
      }
      catch(excptn)
      {
       console.log("METHOD: 'showPersonProperties' - Exception: '"+ excptn.name + "'  -  " + excptn.message);
       throw excptn;
      }
      finally
      {
       console.log("METHOD: 'showPersonProperties' EXITED.");
      }
     }

    So I'm a bit confused as to how to extract the properties that I want to look at, unless this might be some kind of situation where permissions might be a factor.

    Any help would be greatly appreciated.

    Thanks.

    Henry

    Wednesday, March 29, 2017 6:08 PM

All replies

  • Hi Henry,

    If the "targetUser" can't exists, this exception will occurs, please make sure the user exists.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, March 30, 2017 9:08 AM
    Moderator
  • Dennis, I've checked the myProperties object coming in to the success method and its not ever been a value of 'undefined' is it possible that its coming back empty? And if so then how would I check it to see if it is empty? I was able to get my own properties just fine and could even pull out some of the individual properties that belong to me. When I got the exception I was testing using the name of the one of the people that I work with, as I'm trying to develop this page to react the selection of different members from my team, available in a drop-down select box and I believe that I have their names spelled right. This is a local on-premises sharepoint 2013 environment that I'm working in. So unless the domain\\username format  that I'm using is somehow wrong, then the only other thing that I can think of which could be a problem, might be my permissions for accessing such data. Let me know if any of the above possibilities that I've mentioned might be possibilities.

    Thanks.

    Henry

     
    Thursday, March 30, 2017 5:27 PM
  • Hi,

    The  "domain\\username" format is right.

    Please add the log like this:

    var targetUser = domain + sprtr + mnfctrdUserName;
    console.log("targetUser:"+targetUser);

    Then then check if the user exists or not using a people picker column.

    Or we can use jQuery Ajax with REST API to get User Profile Properties.

    http://www.vrdmn.com/2013/07/sharepoint-2013-get-userprofile.html

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, April 3, 2017 7:31 AM
    Moderator