18.09.2011 I have posted a new solution which makes this one obsolete. You find the new one here
09.09.2010 Updated the function “getUserInfo”. It no longer requires the list GUID for the user list to be specified in the script.
31.10.2009: Small update for default picture in the example CEWP.
This article describes how to access the “user profile” under WSS 3.0 via javascript. The method used is a query trough the webservice lists.asmx.
I use some code (“interaction.js” and stringBuffer.js”) created by Erucy and published on codeplex.
The jQuery-library is found here. The pictures and the sourcecode refers to jquery-1.3.2.min. If you download another version, be sure to update the script reference in the sourcecode.
As always we begin like this:
Create a document library to hold your scripts (or a folder on the root created in SharePoint Designer). In this example i have made a document library with a relative URL of “/test/English/Javascript” (a subsite named “test” with a subsite named “English” with a document library named “Javascript”):

You can call this script from any page. In this example i will place it on Default.aspx.
The sourcecode for the “AccessUserProfileInWSS.js” looks like this:
/* getUserInfo - Returns "user info" data from user list in WSS 3.0 (not MOSS user profile)
* ---------------------------------------------
* Created by Alexander Bautz
* alexander.bautz@gmail.com
* http://sharepointjavascript.wordpress.com
* LastMod: 20.09.2009
* ---------------------------------------------
Refer these scripts:
interaction.js // Erucy - http://spjslib.codeplex.com
stringBuffer.js // Erucy - http://spjslib.codeplex.com
jQuery // http://jQuery.com
Use:
var ui = getUserInfo(); // If UserId is not specified it assumes it's logged in user (_spUserId)
alert(ui.Title);
*/
function getUserInfo(UserId){
wsBaseUrl = '/_vti_bin/';
var uiObj = {};
if(typeof(UserId)=="undefined" || UserId=='')UserId = _spUserId;
var arrOfFields = ['ID', 'Name', 'Title', 'EMail', 'Department', 'JobTitle', 'Notes', 'Picture',
'IsSiteAdmin', 'Created', 'Author', 'Modified', 'Editor', 'SipAddress', 'Deleted'];
var item = getItemById('UserInfo',UserId,arrOfFields);
if(item != null){
for(i=0;i<arrOfFields.length;i++){
if(item[arrOfFields[i]]!=null){
uiObj[arrOfFields[i]] = item[arrOfFields[i]];
}else{
uiObj[arrOfFields[i]] = '';
}
}
return uiObj;
}else{
for(i=0;i<arrOfFields.length;i++){
uiObj[arrOfFields[i]] = "User with id " + UserId + " not found.";
}
return uiObj;
}
}
Save this as a text file and rename to “AccessUserProfileInWSS.js”, then upload to the library as shown above.
You call the script from a standard CEWP like this:

Sourcecode for CEWP:
<script type="text/javascript" src="/test/English/Javascript/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/test/English/Javascript/interaction.js"></script>
<script type="text/javascript" src="/test/English/Javascript/stringBuffer.js"></script>
<script type="text/javascript" src="/test/English/Javascript/AccessUserProfileInWSS.js"></script>
<script type="text/javascript">
var ui = getUserInfo(); // If UserId is not specified it assumes it's logged in user (_spUserId)
picSrc = '/_layouts/images/person.gif';
if(ui.Picture!=''){
picSrc = ui.Picture.split(', ')[0]
}
var str = '';
str += "Accountname: " + ui.Name + "<br>";
str += "Full name: " + ui.Title + "<br>";
str += "E-mail: " + ui.EMail + "<br>";
str += "Department: " + ui.Department + "<br>";
str += "<img alt='' src='" + picSrc + "' />";
document.write(str);
</script>
And you get a result like this:

I will follow up this article with an article describing how to hide or show form fields based on membership – or not membership – in a SharePoint group.
Alexander
October 31, 2009 at 9:46 am |
Hi,
I have updated the code in the CEWP to have a default picture.
Your other question is best answered by pointing you in he direction of the function “setFieldValue” from the file “fieldutility.js” found here:
http://spjslib.codeplex.com/
Alexander
January 21, 2010 at 4:43 pm |
Hello Alexander,
Can u please send me the stringBuffer.js and interaction.js file ?
Help is highly appreciated.
Regards.
Bhavesha
January 22, 2010 at 12:01 am
Hi,
The files are found here:
http://spjslib.codeplex.com/.
It is not me who have made these scripts, and i feel it it right that you get the files from the author directly.
Sorry for the inconvenience, but to honor the author, please visit his site and download them from there.
Alexander
February 5, 2010 at 4:24 pm |
hi,
is it possible to display information of a client and not of the current user?
the name of the client stands in the field “client” in dispform.aspx.
thanks
February 5, 2010 at 5:16 pm
Jan,
there are several ways to prepopulate fields on the “NewForm”. One of the simplest is least secure is through the use of query strings.
The DispForm should already have existing data which would make is easier to manipulate.
Can you provide more details of what you’re trying to do?
February 6, 2010 at 6:24 pm
Get the userId from the “client” field in dispForm like this:
<script type="text/javascript" src="../../Javascript/jquery-1.3.2.min.js"></script> <script type="text/javascript"> fields = init_fields(); // Find the userId from a people picker in DispForm var userIdRaw = $(fields['client']).find('.ms-formbody a').attr('href'); var userId = userIdRaw.substring(userIdRaw.indexOf('=')+1); // Here is the userId for the person in the people picker alert(userId); function init_fields(){ var res = {}; $("td.ms-formbody").each(function(){ if($(this).html().indexOf('FieldInternalName="')<0) return; var start = $(this).html().indexOf('FieldInternalName="')+19; var stopp = $(this).html().indexOf('FieldType="')-7; var nm = $(this).html().substring(start,stopp); res[nm] = this.parentNode; }); return res; } </script>The “Show field:” in list settings for the people picker must be one of the “Name” options as this script gets the id from the link to the User information page.
Alexander
February 16, 2010 at 12:37 am |
[...] The script “AccessUserProfileInWSS.js” is found here. [...]
February 24, 2010 at 4:53 pm |
thanks for your help.
now it works.
jan
May 19, 2010 at 10:37 pm |
You are absolutely awesome Alex. So helpful to all of us. Thank you for the great work!
July 19, 2010 at 6:58 pm |
I have a question about this comment:
// If your site collection resides on a managed path, “wsBaseUrl” must reflect the root of your site collection like this:
25 // wsBaseUrl = ‘/myManagedPath/_vti_bin/’;
I’m new to this, so I appoligize if this is a dumb quesiton… how do I know if my site resides on a managed path?
July 20, 2010 at 12:24 am
Hi,
If the site collection is not on the root, it is on a managed path.
If the site collection resides on this address: http://acme.com, it is not a managed path.
If it resides on http://acme.com/sites/YourSiteCollection, it does – and the managed pathe will be “/sites/YourSiteCollection”.
Alexander
October 15, 2010 at 4:59 pm |
Great, working like a charm, also with sharepoint foundation.
Thank you very much
October 18, 2010 at 10:14 pm |
I’ve been using this previously and it’s great.
I notice that you now say that list ID isn’t necessary, but I’ve a bit confused about what you mean:-
“Define userListGuid (list guid of the user list on your root site) as variable accessible to this script”.
Where do I declare that?
Also, in my set up there’s different “people and groups” lists used for different sites. Is there one overall one I can access, or do I need to update it depending on which site the app’s running on?
Also, the managed path reference seems to have gone. Is that not needed any more, or I am missing it somewhere?
Thanks.
October 19, 2010 at 12:04 am
Hi,
After the update 09.09.2010 i didn’t remove all traces of the “list GUID requirements”. I have removed them now – Thank you for noticing!
Managed path is no longer an issue.
In a site collection there are only one “Userinfo list”. Even if a subsite do not inherit security, all users and groups are defined in the site collection root.
Alexander
October 18, 2010 at 10:19 pm |
I got a bit confused by the rating system and seem to have rated my own comment. I finally figured out you vote for the article by clicking on the stars at the top. I assumed that was just a display originally.
November 26, 2010 at 4:06 am |
Hi,
This scripts is exactly what I was looking for (and I lost count of how many I looked before)!! But I must have done something wrong because the user information that is showing is not mine.. Any ideas?
And have you posted already the article about the membership?
Thanks!
November 28, 2010 at 10:16 am
Hi,
I need some more information here:
1. Do you get a completely random result, or do you get the same result every time (the same person)?
2. Is it 2007 or 2010?
3. Is the site on a managed path?
Anything else that might be worth mentioning?
Alexander
December 1, 2010 at 3:18 pm
Thanks for the reply.
1. I always get the same result. Each person that logs in get a single user, but also not the correct user.
2. It’s 2007
3. Yes
December 1, 2010 at 11:57 pm
Could you please try to replace the text ‘UserInfo’ in line 25 in the code with the actual list GUID of the user list.
To get the GUID, go to the “People and groups” list, right click – view source – search for ctx.listName.
Alexander
March 9, 2011 at 6:10 pm |
Dear Alexander,
I had the same issue Christianne mentioned before – my subsite is on a managed path. I tried with alerts in the script and identified that the ID of the subsite on a managed path can have a different meaning on the mastersite. I had still a copy of the old sourcecode of your script and added the listname and the managed path and it was working like a charm
I don’t have access to the master site information, therefore I don’t know the exact reason for the difference.
BR
Wyl
March 13, 2011 at 8:43 am
Hi,
Managed paths always make things a bit harder… To have this script pull information from the right list when on a managed path, change the wsBaseUrl in line 20 like this:
/myManagedPath/_vti_bin/
Alexander
March 23, 2011 at 11:02 pm |
Hi Alex,
Great post (this and the related on on filtering views by group). I have 2 questions. The first is about security: do all authenticated users, even very limited ones, have access to the lists API via this sort of client-side scripting? Also, in 2010 (I realize you’re not explicitly supporting it) getItemById is returning null for all users I’ve tried (administrators mostly). I tried replacing the UserInfo reference with the GUID from _layouts/people.aspx.
This is all related to 2010, so I may be swimming in my own creek.
March 25, 2011 at 10:53 pm
I think it would be available for all users, but it depends upon the configuration. It have to be tested in your local setup to be sure.
This code should work in both 2007 and 2010, but might be a bit tricky if your site resides on a managed path.
Can you provide some more info? – if possible, send me some screenshots.
You find my email here
Alexander
April 20, 2011 at 9:59 pm |
I liked this article. It helped me get the user profile properties. I’m now trying to display them within a content editor web part. But when I placed the “document.write” command in there, it shows only a white screen with my text. The rest of my SharePoint page does not appear.
It’s frustrating. All I want to do is display the text. I look on jquery.com and other places and I find examples for all sorts of complicated things but not displaying text. I don’t want to do an alert window either.
Paul
April 23, 2011 at 9:19 am
Hi,
Add a div in the top of the CEWP like this
Then change the line with document.write like this:
$("#myPlaceHolder").html(str)Alexander
April 28, 2011 at 12:35 am |
Alexander, that sounds like it should work, but the text that I want to appear does not appear. I may have a Javascript error. Let me debug it and get back to you. Thanks.
Paul
May 24, 2011 at 10:23 am |
Hi Team,
Can you tell me what is standard CEWP ? Where i can get that ? What webpart i can add in my page and write this javascript to check ?
Please give me the answer here or email me. It’s really appreciable if you can help me quickly..
May 24, 2011 at 10:26 am
Hi, The CEWP is the Content Editor Web Part that is shipped with both WSS, MOSS and SP2010. Edit page and insert it into any webpage.
Alexander
May 24, 2011 at 11:20 am |
Hi Alexander,
Wow I have checked my installed Sharepoint 2007. But there is no such webpart. I found Picture and other webpart but not this one.
Can you tell me from where i can add this content editor webpart in my sharepoint 2007 ? Or something i need to active or like ?
May 24, 2011 at 11:33 am
You should find it under the “Miscellaneous” section. If you do not find it, it may have been removed by your server administrator.
Alexander
October 3, 2011 at 5:30 pm |
Hi,
thanks for the code and it worked with current user.
But when i gave other user id like (domain\\userid) it is returning the user is not found.
I tried with different ids but the same result.
Kindly help me out in this
October 3, 2011 at 6:23 pm
HI,
The code found in this page does not support getting the user by login name. Follow the link to the new version in the top of this article.
Alexander
January 23, 2012 at 5:09 pm |
[...] Accessing user profile information in SharePoint with javascript – updated version I have previously posted a solution for pulling user information from the built-in user information list in SharePoint (found in WSS 3.0, MOSS 2007 and SharePoint 2010 both foundation and server). This is NOT the user profile found in MOSS 2007 and in SharePoint 2010 server. You find the solution here [...]