Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

standalone call for "UserProfileProperties" #38

Closed
YakQin opened this issue Nov 21, 2018 · 5 comments
Closed

standalone call for "UserProfileProperties" #38

YakQin opened this issue Nov 21, 2018 · 5 comments
Assignees
Milestone

Comments

@YakQin
Copy link

YakQin commented Nov 21, 2018

Hi,
again this is a great library!

if I only need the "UserProfileProperties" the call will return all other "Person Properties" though the API will return only "UserProfileProperties" with function sprLib.user(options).profile('UserProfileProperties')

from the performance perspective the call returns a lot of info that we don't need, especially when the user has many peers or direct reports etc. If possible you may create a standalone function for UserProfileProperties only with below query :

Url = "https://xx.sharepoint.com/teams/3wuam/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)/UserProfileProperties?@v='i:0%23.f|membership|" + mailID + "'"

with above query we can get the UserProfileProperties much faster

just a suggestion but the existing functions are already great to go with :)

@gitbrent
Copy link
Owner

Hi @YakQin

The library already has the ability to query a single profile property (as opposed to all of them) - is this what you're looking for?

sprLib.user().profile('PictureUrl')

.--------------------------------------------------------------------------------------------------------------------------------------.
| Prop Name  |                                                       Prop Value                                                        |
|------------|-------------------------------------------------------------------------------------------------------------------------|
| PictureUrl | "https://BLAH-my.sharepoint.com:443/User%20Photos/Profile%20Pictures/admin_me_onmicrosoft_com_MThumb.jpg?t=63631247080" |
'--------------------------------------------------------------------------------------------------------------------------------------'

It runs the query you show in the "URL" above:

screen shot 2018-11-27 at 22 26 48

@YakQin
Copy link
Author

YakQin commented Nov 28, 2018

to make long story short, if I want to get the "Department" and if I run query sprLib.user(options).profile("UserProfileProperties"), the query will all return "Peers", "DirectReports" etc, however I don't need those details. so the query returns a lot of data that is not needed. we have a waste here.
If we have standalone query to only return "UserProfileProperties", then it is more clear when we only need part of "UserProfileProperties"
As a workaround, I used below:

	function getOrg(mailID, obj) {
		sprLib.rest({
				url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)/UserProfileProperties?@v='i:0%23.f|membership|" + mailID + "'"
			})
			.then(function (arrItems) {
				var props = arrItems[0].UserProfileProperties.results
				$.each(props, function (i, prop) {
					if (prop.Key == 'Department') {
						obj.html(prop.Value)
					}
				})
			})
			.catch(function (errMsg) {})
	}

@YakQin
Copy link
Author

YakQin commented Nov 28, 2018

Adding only the url
url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)/UserProfileProperties?@v='i:0%23.f|membership|" + mailID + "'"

@gitbrent gitbrent added this to the 1.9.0 milestone Dec 2, 2018
@gitbrent gitbrent self-assigned this Dec 2, 2018
@gitbrent
Copy link
Owner

gitbrent commented Dec 3, 2018

Gotcha: Just query what we need, not the entire result set.

So, even better than pulling all UserProfileProperties and filtering out what was requested, the REST API allows for a call to a single profile property (MSDN).

This is the call i've implemented, it's super efficient and the smallest possible network footprint.

In the case of multiple properties, then your code above is used as there is no equivalent to GetUserProfilePropertyFor for multiple properties.

screen shot 2018-12-02 at 16 17 38

screen shot 2018-12-02 at 16 17 50

screen shot 2018-12-02 at 16 18 03

@gitbrent gitbrent closed this as completed Dec 3, 2018
@YakQin
Copy link
Author

YakQin commented Dec 3, 2018

This is perfect ! thanks a lot

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants