Get current user’s LoginName Ecmascript Sharepoint 2010

Share this post :

This post  will contain two snippets one to get the current user’s LoginName on page Load using the ECMAScript and the other one to get the current User’s Profile properties like “Employe Id” using ECMAScript and JQuery.

Get Current Users LoginName – For testing purposes, copy and paste the below code into a content editor webpart

<script type=”text/javascript”>
var context = null;
var web = null;
var currentUser = null;

ExecuteOrDelayUntilScriptLoaded(GetUserLoginName, “sp.js”);

function GetUserLoginName() {

context = new SP.ClientContext.get_current();
web = context.get_web();
this._currentUser = web.get_currentUser();
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),

Function.createDelegate(this, this.onFailureMethod));
function onSuccessMethod(sender, args) {
var today = new Date();
alert(‘ Name:’ + this._currentUser.get_title() + ‘\n Login:’ + this._currentUser.get_loginName());
function onFaiureMethod(sender, args) {
alert(‘request failed ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());


Share this post :
Tags: SharePoint 2010