none
Properly format targetuser used for reading user profile using jsom - Exception related or not? RRS feed

  • Question

  • I'm trying to read user profile data using JSOM in an on-premise sharepoint 2013 environment. So according to documentation that I've read my target user should be in the format of "domain\username" (which in my case will turn out to be something looking like this:  "domain1stpart.domain2ndpart.edu\\dduck" or ""domain1stpart.domain2ndpart.edu\\dduck@domain2ndpart.edu").

    Can someone confirm that the two backslashes are required because the second backslash is being escaped by the first one?

    Can someone also tell me if the username part needs to have a domain part after it or not to make it a valid username?

    My problem in the block of code below might be that I'm not quite formatting the "targetuser" value correctly.

    Here's the code having the problem(in the success method shown below):

     function getUserProperties(slctdTmMmbr,slctdName)
     {  
      try
      {
       console.log("METHOD: 'getUserProperties' ENTERED.");
       
       var mnfctrdUserName = ConstructUserName(slctdTmMmbr,slctdName);
       var domain = "xxxxxxx.xxxxxx.xxx";
       var sprtr = "\\";
       var targetUser = domain + sprtr + mnfctrdUserName;
       var prprtsCntxt = new SP.ClientContext.get_current();
       var peopleManager = new SP.UserProfiles.PeopleManager(prprtsCntxt);
       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 dsplyName = myProperties.get_displayName();
       var accntName = myProperties.get_accountName();
       var email = myProperties.get_email();
       var title = myProperties.get_title();
       var pictureUrl = myProperties.get_pictureUrl();
      }
      catch(excptn)
      {
       console.log("METHOD: 'showPersonProperties' - Exception: '"+ excptn.name + "'  -  " + excptn.message);
       throw excptn;
      }
      finally
      {
       console.log("METHOD: 'showPersonProperties' EXITED.");
      }
     }

    I'm just trying to resolve the exception (SCRIPT5022:SCRIPT5022: Object reference not set to an instance of an object on server. The object is associated with method GetPropertiesFor.) that I keep getting when control reaches this line in the second method:

    var dsplyName = myProperties.get_displayName();

    Its like the myProperties object is undefined or something, but when I hover over it in the IE debugger I get this verbiage or description of it:

    myProperties    [object (SP.UserProfiles.PersonProperties)]

    Which to me looks like it does actually contain some kind of formatted object containing data.

    This makes no sense unless its just an empty object of some kind. It also makes no sense that it would not recognize the username that I passed it unless for some reason that user has not been added to our sharepoint, as that represents one of the actual people that I actually work with, so I  know they at least should be valid.

    Thanks for the help.

    HDV

    Friday, March 31, 2017 3:26 PM

All replies

  • 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
  • Dennis,

    I added the the line that you suggested above to log the target user, it looks right. Based on what I'm seeing the first backslash character must escape the second one. Other than that the target looks like its being formatted correctly. I asked a colleague, if he could tell if any or all of that information was there, and he couldn't tell, but did sya that perhaps we're not getting everything propagated down to our test system, and that might be why I'm not able to read the user profiles. Is there anything I can do to verify one way or another whether they are actually being formatted or not? Please let me know if so.

    Thanks.

    Henry

    Monday, April 3, 2017 7:28 PM
  • Please check the thread:

    https://social.msdn.microsoft.com/Forums/office/en-US/a228e795-d4e5-48a4-b786-72f572fb37a3/trying-to-read-user-profile-properties-using-rest-api?forum=sharepointdevelopment#4bd097f6-adb6-4427-a3d7-2ee07ae04d48


    Thanks, Amit Kumar, LinkedIn Profile ** My Blog

    Friday, April 7, 2017 7:32 AM