Thursday, January 23, 2014

Get user profile properties in SharePoint with Javascript/Jquery object model

Hello,

This post will show you, how you can access theuser profile information in SharePoint with javascript using client object model.

Thanks to Alexander for writing this post as it was much helpful.

Insert this code in a CEWP

1<script type="text/javascript"src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
2<script type="text/javascript" src="/test/EMSKJS/spjs-utility.js"></script>
3<script type="text/javascript">
4 
5var userInfoObj = getUserInfo_v2(_spUserId);
6var name = userInfoObj.Title;
7var email = userInfoObj.EMail;
8</script>
I have incorporated the new
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
Download
You can download the file “spjs-utility.js” here. Ensure you pick the version dated 18.09.2011, or newer.

No comments:

Post a Comment