Click here to Skip to main content
15,886,067 members
Articles / Productivity Apps and Services / Sharepoint / SharePoint 2013
Tip/Trick

User Profile Service in SharePoint 2013

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
8 Aug 2014CPOL 17K   6
User profile service in SharePoint 2013

Introduction

Welcome to a new tip of User profile Service in SharePoint 2013. Today, I will be showing you a beautiful way to get Current logged in User’s details on a page using JavaScript.

So let’s do it:

  • Create a new Page
  • Add a Content Editor web part
  • Place the below code in it.

Code

HTML
-----The following HTML code is used to display the Current logged in User name on a Content Editor Web Part.
Name- <span id="username"></span><br/>

---- The following code calls the sp service and append the HTML code replacing by the value.

<script type="text/javascript"> 
  var thisUserAccount ;         
    $(document).ready(function() {
    thisUserAccount= $().SPServices.SPGetCurrentUser({
    fieldNames: ["Title","Department","Email"],
    debug: false
});
 
var nametag="<span id=\"username\">"+thisUserAccount.Title+"</span>";
 
$('#username').replaceWith(nametag);
 
}   
    ); </script>

This is the result on the Home page:

As you can see, the name comes up on the page load of the site. In a similar way, you can have the following attributes like Department, Email, etc. to your page.

FIELD NAME INTERNAL NAME
Account Name
Name Title
Work e-mail Email
About me Notes
Picture Picture
Department Department
Job Title JobTitle
SIP Address SipAddress
First name FirstName
Last Name LastName
Work phone WorkPhone
Office Office
User name UserName
Web site WebSite
Responsibilities SPResponsibility

You just have to make a change like:

  • thisUserAccount.Title
  • thisUserAccount.Email
  • thisUserAccount.Department

in the code and hence the purpose will be served.

Till then, keep learning.

Cheers!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Argentina Argentina
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionThe code is not working in SHP 2013 Pin
Farfalla_Fn8-Dec-14 1:39
Farfalla_Fn8-Dec-14 1:39 
AnswerRe: The code is not working in SHP 2013 Pin
MANPREET SINGH10-Dec-14 15:45
MANPREET SINGH10-Dec-14 15:45 
QuestionI tried your codes and download both JS file, but still it's not working. Pin
Member 1118856928-Oct-14 20:29
Member 1118856928-Oct-14 20:29 
AnswerRe: I tried your codes and download both JS file, but still it's not working. Pin
MANPREET SINGH10-Dec-14 15:46
MANPREET SINGH10-Dec-14 15:46 
QuestionIts not working Pin
sandeepkumarvemula13-Aug-14 1:16
sandeepkumarvemula13-Aug-14 1:16 
AnswerRe: Its not working Pin
MANPREET SINGH13-Aug-14 11:10
MANPREET SINGH13-Aug-14 11:10 
What type of jquery files are you using, You should refer to jquery.SPServices-0.7.2.min.js and jquery-1.8.3.min.js to run the above code in SharePoint 2013

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.