SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Has anyone managed to use SPServices to display the current logged in username in a content webpart?

Is this even possible in 2013 (online)?

share|improve this question
up vote 3 down vote accepted

You must have your reasons why using SPServices for this mundane task, because the CSOM in SharePoint 2010 and even more in 2013 can help you do that using out-of-the-box routines. Of course it is only working in the current Site Collection.

See example here bellow:

var currentUser;

function init(){
 this.clientContext = new SP.ClientContext.get_current();
 this.oWeb = clientContext.get_web();
 currentUser = this.oWeb.get_currentUser();
 this.clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded), Function.createDelegate(this,this.onQueryFailed));
function onQuerySucceeded() {
 document.getElementById("currentUser").innerHTML = currentUser.get_loginName(); 
function onQueryFailed(sender, args) {
 alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
<div>Current Logged-In User:<label id="currentUser"></label></div>
share|improve this answer
Thanks for the reply, happy to do it anyway that works...but would prefer to achieve this via the SP ui rather than have use visual studio. Thanks for the input. – Stephen Feb 27 '13 at 21:47
actually that code works perfectly directly in the CEWP, reason for which i've proposed it. Just wrap it in a script tab, put it in a .js file, via Notepad, upload it to a Document Library, add in the page a CEWP and reference the JS. – Marius Constantinescu - MVP Feb 27 '13 at 21:53
Hi There, I have this working on my site but its returning my full details i.e. i:0#.f|m​embership|​​​ where i would prefer to just have the Firstname or Firstname surname. Thanks again. – Stephen Feb 28 '13 at 10:47
Stephen, it seems you use Claims - that is why you get the funny Account name. Available should be get_title(), but many other properties are only available via the User Profile (which of course requires at least Standard edition). See here for a exact example… (you need to ask for FirstName and LastName) – Marius Constantinescu - MVP Feb 28 '13 at 14:20
Thanks for that...not sure if I have standard edition or not...I have seen this link blogpost… which looks promosing.. – Stephen Feb 28 '13 at 14:28

The easiest is use JavaScript global variable _spUserId. More read is available at

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.