Get Current User Account Name, E-Mail using Javascript Client Object Model in SharePoint 2013

Get Current User Account Name, E-Mail in JavaScript Client Object Model
You can use this code in Content Editor/Script editor or anywhere in SharePoint artifacts like Pages, Page Layouts, Master pages, or external JavaScript files.

<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(getCurrentUser, "sp.js");

var currentUser;

function getCurrentUser(){
var ctx= new SP.ClientContext.get_current();
var web = ctx.get_web();
currentUser = web.get_currentUser();
ctx.executeQueryAsync(onSuccess, onFailure);

function onSuccess() {
alert(currentUser.get_title()); // Domain\Account 
document.getElementById('userLogin').innerHTML = currentUser.get_loginName(); 

function onFailure() {
alert('request failed' + args.get_message() + '\n' + args.get_stackTrace());


<div>Currently Logged User:
    <span id="userLogin"></span>

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *