locked
Slow performance when getting user properties RRS feed

  • Question

  • Hi, guys
    I'm using the PeopleManager.getMyProperties method to get the properties for the logged in user. This works fine, but it's time consuming. I really need to get a better performance, but I'm at a loss.

    I assume getMyProperties retrieves ALL user properties, which is a lot. Can I make it only fetch what I actually need to reduce the amount of data being sent over the network?

    Or is the getPropertiesFor method a better option performance-wise?

    This is an excerpt of my JavaScript code:

    SP.SOD.executeFunc('SP.Taxonomy.js', 'SP.ClientContext', function(){
    	SP.SOD.executeFunc('SP.UserProfiles.js', 'SP.ClientContext', function(){
    		var clientContext = new SP.ClientContext.get_current();
    		var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
    		userProperties = peopleManager.getMyProperties();
    		clientContext.load(userProperties);
    		clientContext.executeQueryAsync(userObjectSucceded, userObjectFailed)
    
    		function userObjectFailed(sender, args){
    			console.log("GetUserObject (userObjectFailed): " + args.get_message());
    		}
    
    		function userObjectSucceded(){
    			try {
    				var accountName = userProperties.get_userProfileProperties()["AccountName"];
    				var workEmail = userProperties.get_userProfileProperties()['WorkEmail'];
    				var organization = userProperties.get_userProfileProperties()['Organization'];
    				var firstName = userProperties.get_userProfileProperties()["FirstName"];
    				var lastName = userProperties.get_userProfileProperties()["LastName"];
    				currentUser = ({userid: accountName, email: workEmail, organization: organization, firstName: firstName, lastName: lastName});
    			}
    			catch (err) {
    				console.log(err);
    			}
    		}
    	});
    });

    Any information on the subject is appreciated. Thanks.

    Friday, February 5, 2016 9:26 AM

Answers

  • Thanks again, but this article still uses the getUserProfilePropertiesFor method which requires the Account Name. I don't have the Account Name, I want the properties for the current user. That's why I'm using getMyProperties, which gives ALL properties for the current user.

    My question was really if it is possible to get just a set of properties for the current user. My guess is now that it's not possible. But thanks for your time.

    Thursday, February 25, 2016 7:51 AM

All replies

  • Hi Papageno,

    I would suggest you can try to load specific properties instead load all properties like below:

    clientContext.load(userProperties, 'FirstName', 'AccountName');

    Then test if the performance raise up.

    If the issue still exists, I would suggest you can try to use Internet Explorer and Fiddler to trace in which line it causes the slow performance.

    More information:

    Fiddler

    Using the Profiler Tool to analyze the performance of your code

    Thanks

    Best Regards


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


    Sunday, February 7, 2016 3:16 PM
  • Hi Jerry and thanks for your answer.

    Yes, that's exactly what I want to do. Unfortenately, simply extending the load method with the named fields isn't enough. When doing so, the executeQueryAsync calls the fail function stating Field or property "FirstName" does not exist.

    Presumably I need to tell the people manager which fields to collect. Much like viewfields in a CAML query.

    That sounds like a good idea. The problem is that I just don't know how to do that.

    I could of course use the getUserProfilePropertiesFor method. That would give me the option to specify the properties I want, but that would also require the Account Name which I don't have at this point. And to get the Account Name, I would still need to use getMyProperties. So that's no point.

    Does anyone have any idea how to get around this?

    Sunday, February 7, 2016 7:01 PM
  • Hi Papageno,

    Here is a code demo (the last code snippet in the article) about collect specific user properties fields for your reference:

    How to: Retrieve user profile properties by using the JavaScript object model in SharePoint 2013

    Thanks

    Best Regards


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

    Tuesday, February 23, 2016 1:57 AM
  • Thanks again, but this article still uses the getUserProfilePropertiesFor method which requires the Account Name. I don't have the Account Name, I want the properties for the current user. That's why I'm using getMyProperties, which gives ALL properties for the current user.

    My question was really if it is possible to get just a set of properties for the current user. My guess is now that it's not possible. But thanks for your time.

    Thursday, February 25, 2016 7:51 AM