Get user profile by ID

Jun 21, 2011 at 3:49 PM

Hi,

Can I access the user profile using the info in a people field (by the form 5;#LastName, FirstName? I've tried to use the GetUserProfileByIndex with no luck and can't find any better...

/Fredrik

Coordinator
Jun 25, 2011 at 3:36 PM

Fredrik:

I just did a quick test and was able to retrieve a user profile with GetUserProfileByIndex just by supplying the index number, as shown in the SDK:

index: 5,

Give that a try.

M.

Coordinator
Jun 26, 2011 at 2:19 AM

Fredrik:

I take this back. It was bugging me in the back of my mind a bit and I just looked at the implementation in SPServices for GetUserProfileByIndex. It turns out that I'm not actually passing any parameters to the operation, which is basically a bug.

If you add the following code at line 855 in v0.6.2, then you'll have the proper implementation:

   case "GetUserProfileByIndex":
    addToPayload(opt, ["index"]);
    break;

I'll get this fix into the first alpha for v0.6.3, but there it is if you want to use it. I'm not certain what value index should hold. When I pass the ID for the user with this fix, I do not get the results I'd pexpect.

M.

Coordinator
Jun 26, 2011 at 2:34 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Jun 26, 2011 at 2:36 AM

A little more research...

You should use GetUserProfileByName, if possible. It seems that GetUserProfileByIndex hardly does what one would expect, vis http://sharepointsharpener.wordpress.com/2008/08/08/userprofileservice-web-service-returns-multiple-instances-of-user-profiles-with-identical-names/

M.

Coordinator
Jun 26, 2011 at 3:14 AM

New post on my blog about this:
http://sympmarc.com/2011/06/25/confusion-about-the-userprofile-web-services-getuserprofilebyindex-operation/

M.

Jun 27, 2011 at 9:15 AM

The update in the alpha works, and when I think about it probably as expected. The UserProfileService queries the user profiles and that's not site collection specific so the user index id is the one there, not in the current site.

So the only way to get the user profile from the id provided in a people field is to first query the User Information List? Don't you need full permission to query that list?

/Fredrik

Jun 27, 2011 at 12:27 PM

I haven't had any luck with querying that list *without* elevated privileges.  I'm interested in your results.  Let us know what you find.

Cheers,

Matt

Coordinator
Jun 27, 2011 at 12:33 PM

The User Information List is specific per Site Collection. That's why I suggest using GetUserProfileByName instead of GetUserProfileByIndex. It seems that in order to identify the right user profile using GetUserProfileByIndex, you'd need to loop through them all until you found the right name, anyway. At least that's how I read those blog posts.

I've read the UIL successfully in the past, but the user doing so needs to have permissions to see it. The easiest proxy for that is whether they can see People and Groups in the Quick Launch.

M.

Jun 28, 2011 at 9:59 AM

I think I tried all pretty ways to solve this now, but still haven't found any working. Solved it in a not so pretty way instead.

I created an empty aspx page (peoplefunc.aspx), everything stripped out, with a DVWP on showing only the peoplefield. The people field in a DVWP shows the SIP-address that can be used in GetUserProfileByName.

<xsl:value-of select="substring-before(substring-after(@Responsible, 'sip:'), '@')" />

I then get the value with ajax to call the web service.

	$.ajax({
		url: 'http://info.global.Company.com/demo/OrgChart/Documents/peoplefunc.aspx?ID='+itemId,
		success: function(data) {
	  	$().SPServices({
			operation: "GetUserProfileByName",
			AccountName: $(data).find('div').text()+'@Company.com',
			completefunc: function (xData, Status) {				
				 alert($(xData.responseXML).find("Name:contains('First')").parent().find('Value').text());
			}
		});
	  }
	});

Far from a pretty solution, but ended up to be quite quick

 

Coordinator
Jun 28, 2011 at 12:10 PM

Well, it seems as though that would work. I would think that you'd also be able to look up the SIP-address from the User Information List using GetListItems, assuming the user running the page had permissions.

If it were the current user, you could use $().SPServices.SPGetCurrentUser, but it doesn't look like that is the case.

M.

Jun 28, 2011 at 2:12 PM

Thousands of users, so don’t think UIL will work this time, even though that might be smother.

Tnx

Coordinator
Jun 28, 2011 at 2:21 PM

Looking up in the UIL ought to be no less efficient than your peoplefunc.aspx page, but it seems like you have a solution that works for you.

M.

Jun 28, 2011 at 3:13 PM

I actually think the UIL is more efficient, but then I had to change the permission for all "reader" users...

Jun 29, 2011 at 10:12 AM

Just my little FYI as I am currently on WSS only. We use the UIL and basically going to this list and going to its permissions give "Authenticated Users" read access to the list. This has worked every time but as I said, we only have WSS so it is what works.

Mar 7, 2012 at 4:59 PM

Note to self and other intersted....

CAMLQueryOptions: "<QueryOptions><ExpandUserField>True</ExpandUserField></QueryOptions>",
returns account name, email, and name instead of just the name

Mar 7, 2012 at 7:17 PM

Cool fereko... I'll be adding that to roboCAML in an upcoming version after some testing.  Thanks for the tidbit!

Cheers,

Matt