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
This solution is an updated version of the script – and should hopefully work better with sites on a managed path.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <script type="text/javascript" src="/test/EMSKJS/spjs-utility.js"></script> <script type="text/javascript"> var userInfoObj = getUserInfo_v2(_spUserId); var name = userInfoObj.Title; var email = userInfoObj.EMail; </script>
I have incorporated the new “getUserInfo_v2” in the file “spjs-utility.js”.
The parameter “_spUserId” is provided by SharePoint and represents the current user’s userID.
The function takes one argument which can be a userID or a login name (domainlogin or appname:user). If you use domainuser as a string like this:
var userInfoObj = getUserInfo_v2("contoso\alexander");
Please note the extra “” as it must be escaped in javascript.
The variables “name” and “email” are examples, the full range of “out of the box fields” are:
ID, Name, Title, EMail, Department, JobTitle, Notes, Picture, IsSiteAdmin, Created, Author, Modified, Editor, SipAddress
You can download the file “spjs-utility.js” here. Ensure you pick the version dated 18.09.2011, or newer.
I tried using this and nothing shows up on the screen. I downloaded the above file and placed in a document library and then copied the code above and linked it to a CEWP. I made sure and changed the line 2 to reflect where my file is saved. I save everything but nothing shows in the CEWP box.
I tried also to using this … and nothing comes up. Must be change something other on the script to work?
Hi Rebecca and Steve,
This code does not display anything on the screen. Look at the code and see the variables “name” and “email”.
If you want a “feedback” – alert the variables.
Alexander
Hello Alexander,
Which other fields can i use? Tried het OOB Manager field but returned ‘undefined’, while i know this one is filled.
Hi,
This script does not use the “user profile” from MOSS, it deals with the built in user list. The fields you can access are listed in the function “getUserInfo_v2” and involves: ‘ID’, ‘Name’, ‘Title’, ‘EMail’, ‘Department’, ‘JobTitle’, ‘Notes’, ‘Picture’, ‘IsSiteAdmin’, ‘Created’, ‘Author’, ‘Modified’, ‘Editor’, ‘SipAddress’.
You can however add extra fields add add those to the array.
Alexander
Hi Alexander, this would be really useful for me but I cannot seem to download the utility j.s, he web page is unavailable, can you help please
Kris
Hi,
It looks OK from here – if you have issues with https, try using http (edit the URL). Let me know if it still does not work.
Alexander
Hi,
This solution is good for getting information for users in userinfo list. How to get user profile information which are not added on the site?
Hi,
I do not have access to a MOSS / SharePoint 2010 Server so i have not tested this function:
You must use the “spjs-utility.js” as it uses the function “spjs_wrapSoapRequest” from that library.
Please let me know if it works.
Alexander
Hi, The solution you gave me works for current logged in user. What if I want information of different user? How do I pass user Id to the soap function?
Hi,
Try adding the accountname (domain\user) between these tags
Note the double backslash if the account name is a string and not a variable.
This is not tested as I do not have access to SharePoint server.
Alexander
Hi Alexander,
I have the same needs of Sneha (retrieve domain user’s email), but the function gives me an “undefined” message.
Since the original function works very well, but retrieves only email of persons inside “All People” internal group, could you give me a proper solution to implement the original script?
Hi,
Is there any chance that I could still download the js file? That website is unavailable . Or is there any other place where I could get the file from?
Hi,
The link is updated.
Alexander
are the three equal sign at line 123 of your function getUserInfo_v2 in spjs-utility.js intentional?
Yes, it is.
Alexander
This works great, but is there a way to get the Work/Cell numbers of a user also by using this?
Hi,
You must edit the function “getUserInfo_v2” found in the file “spjs-utility.js” and add the FieldInternalName of your “Work/Cell number field” to the array “arrOfFields”.
Alexander
Hi, Alex very nice Post.I have tried and it works f9 for me.But I want to get the List of all the Colleague of current users. i have read your getUserInfo_v2 function but unable to edit as per my need.
Thanks an advance.
This works for me perfectly. Thank you!
how do we add new fields to the user list
You add fields here as for any other list, but you may need to be site collection administrator.
Alexander
Thanks for the code..
This is working fine except for the field Mobile Phone..
How can we get mobilephone of a user ??
Hi,
Update spjs-utility.js to v1.177 and then use this code:
“YourCustomPropterty” must be the FieldInternalName of the property from the use list.
Alexander
yeah…!! i got mobile phone.. i added the field to the .js file.. 🙂
thank you..
Hi Alexander,
I added field “l” to get City of the user. But I got null as return value. I have admin rights to the site. Not sure what’s the issue. Rest of the field values are retrieved very well.
-Venkatesh R
This script works with SharePoint 2013 with a very minor adjustment.
Replace _SPUserID with _spPageContextInfo.userId
Very useful, thank you.
The parameter “_spUserId” does not seem to be provided on the page. I think it has something to do with my current custom master page. Do you have any suggestions on how I can possibly “import” this field to the page?
Thank you very much.
-Shar Y
Hi,
Are you using SP2010 or 2013? – if so, you can use
Alexander
Hello Alexander,
We try to capture the current users SipAddress on a sharepoint page. We have several solutions that work in IE but no solution that also works in Safari.
Do you have a solution for us?
(We also tried the solution on this page)
Kind regards,
Mario
Hi,
Is this Safari for MAC, IPad or Windows? – any errors in the developer console (if there is such a thing in Safari)?
Alexander
Hello Alexander,
It is Safari on Windows (haven’t tried Mac)
We have turned on the console and got the following errors:
ReferenceError: Can’t find variable: jQuery
ReferenceError: Can’t find variable: getUserInfo_v2
It works fine in IE.
Kind regards,
Mario
Hello Alexander,
It seems the script on the server cannot be read.
So I included the script in the site collection and it works.
The question for me now is why does Safari not read from the server.
Kind regards,
Mario
Hello Alexander,
OK. Found it out.
Completely my mistake.
Thanks for the support.
Kind regards,
Mario
I’m glad you figured it out. Please note that you must not refer the scripts from spjsfiles.com directly. This server is not fast enough to serve the scripts live.
Alexander
I want to assign Te email I’d to a column in Te list how’s that possible
Hi,
Add one line to the code example above:
PS: If you are using SP2013 you must change _spUserId for _spPageContextInfo.userId
Alexander