Get Current User Details Using JavaScript Object Model (jsom) and jQuery in SharePoint 2013/2016/Online

Here, I am explaining how to show current user details using the JavaScript Object Model (JSOM) and jQuery in SharePoint online.

Below is the code to retrieve current user details like display name, user name, email id and user id using Jsom and jQuery in SharePoint.

Open your SharePoint site and go to the web part page and then Edit the web part page -> Add Web parts. And then add a script editor web part into the SharePoint web part page.

Get current user display name, email id, user id in SharePoint 2013/2016/Online using JavaScript Object model (jsom) and jQuery

<script type="text/javascript">  
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('userLoginName').innerHTML = currentUser.get_loginName();   
    document.getElementById('userId').innerHTML = currentUser.get_id();  
    document.getElementById('userTitle').innerHTML = currentUser.get_title();  
    document.getElementById('userEmail').innerHTML = currentUser.get_email();  
function onQueryFailed(sender, args) {  
    alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());  
<div>Current Logged User:  
    <span id="userLoginName"></span></br>  
    <span id="userId"></span></br>  
    <span id="userTitle"></span></br>  
    <span id="userEmail"></span></br>  

You may like following jsom SharePoint tutorials:

Once you execute the jsom code, it will display the current logged in user display name, email, user id and user login name in SharePoint.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

Rajkiran Swain

Rajkiran is currently working as a SharePoint Consultant in QATAR . Rajkiran having 7+ years of experience in Microsoft Technologies such as SharePoint 2019/2016/2013/2010, MOSS 2007,WSS 3.0, Migration, Asp.Net, C#.Net, Sql Server, Ajax, jQuery etc.He is C#Corner MVP (2 Times).

  • […] Get Current User Details Using JavaScript Object Model (jsom) and jQuery in SharePoint 2013/2016/Online […]

  • >