How can I get full name from SPUser? I got him from get_currentUser() from web context. And how can I convert from SPUser to SPFieldUser in JS?

EDIT: I need it to compare, I get from list field SPFieldUser and want to compare it with current user. Or by full name or by domain login (which is better i think). But I cant get both. get_loginName() from web current user doesnt work but . But I get email by _spPageContextInfo.userLoginName or user by userDisplayName. From list I got full user name by get_lookupValue() but cant get login name. But I wish to compare it by domain login or email.

3 Answers 3


You can retrieve current user's display name, id & login name from _spPageContextInfo object.

window.console && console.log('Display Name: ' + _spPageContextInfo.userDisplayName);
window.console && console.log('Login Name: ' + _spPageContextInfo.userLoginName);
window.console && console.log('User Id: ' + _spPageContextInfo.userId);

To set the list item's user field value

var userFld = new SP.FieldUserValue();

// Set the list item 
item.set_item(person_field_column_Name, userFld);
  • Thanks, it work! :) Now have to get from list field a login/mail (think its better than compare by full user name).
    – Rhonin
    Commented Oct 26, 2016 at 6:18
  • userId and lookupId for list item was enough to compare :) I think it works fine. Without domain login /email/full user name, thanks :)
    – Rhonin
    Commented Oct 26, 2016 at 7:05

Please use below method to get all the required information of user...

function getCurrentUserEmail(){
  var clientContext = new SP.ClientContext.get_current();
  this.website = clientContext.get_web();
  this.currentUser = website.get_currentUser();
  clientContext.executeQueryAsync(Function.createDelegate(this, this.onRequestSuccess), Function.createDelegate(this, this.onRequestFail));
function onRequestSuccess(sender, args){
  var curUserEmail = currentUser.get_email();
  var curUserloginName = currentUser.get_loginName();
function onRequestFail(sender, args){
  alert('request failed ' + args.get_message() + '\n'+ args.get_stackTrace());
function getUserInfo(loginName){
  var context = new SP.ClientContext.get_current();
  var userInfoList = context.get_web().get_siteUserInfoList();
  var query = new SP.CamlQuery();
  var viewXml = "<View><Query><Where><Eq><FieldRef Name='Name' /><Value Type='Text'>" + loginName+ "</Value></Eq></Where></Query><RowLimit>1</RowLimit></View>";
  var items = userInfoList.getItems(query);
    if(items.get_count() > 0) {
      var item = items.itemAt(0);
      console.log('User Id: ' + item.ID);
      console.log('First Name: ' + item.FirstName);
      console.log('Last Name: ' + item.LastName);
      console.log('EMail: ' + item.EMail);
      console.log('Name: ' + item.Name);
      console.log('User Name: ' + item.UserName);
  • I try it, get error when using get_loginName(), uncaught error that it wasnt initiated. I need only loginname or full user name.
    – Rhonin
    Commented Oct 26, 2016 at 5:56
  • Can you paste your code here, it seems you are trying to use object before it is loaded(executequery has ran)... Commented Oct 26, 2016 at 7:20
  • I have in method all this executequery... and this method return item to me but I cant use these function. function getUser() { var currentUser = web.get_currentUser(); currentUser.retrieve(); clientContext.load(currentUser); clientContext.executeQueryAsync( function () { // code to execute if success }, function () { onQueryFailed(); }); return currentUser; } So this is why this function dont work on my. Now I know and solved problem in other way :) thx anyway
    – Rhonin
    Commented Oct 26, 2016 at 9:15
  • np....please mark it as answer so that it is helpful to others also...!! Commented Oct 26, 2016 at 9:18

use get_title() to get the full name:

var usertxt = web.get_currentUser();

why do you want to convert an SPUser to an SPFieldUser?

this will explain why I ask the question above, if its to update a list item just use the spuser object

How do I convert SPUser to SPFieldUser?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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