Learning SharePoint   Enhance Your SharePoint Knowledge

Subscribe to Learning SharePoint Subscribe
Twitter Learning SharePointFollow Us
in Learning SharePoint
Check Out Our New SharePoint 2013 series!

Get current user’s LoginName Ecmascript Sharepoint 2010

05/18/2011  
Category: SharePoint 2010


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.load(this._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());
}
</script>

Result-

Subscribe to Learning SharePoint Subscribe
Twitter Learning SharePointFollow Us
in Learning SharePoint
Advertisement

Random Posts

Passing parameters to the dialog sharepoint 2010 Client Object model
Passing parameters to the»

The most asked questions in our Forum below is about how to get the selected items from a list using»

Reporting and Web Applications Using Access
Reporting and Web Applications»

SharePoint 2010 Site Owner’s Manual Flexible Collaboration without Programming Yvonne M. Harryman In this article, based on chapter 10 of»

Set Choice Field value with value from Querystring Sharepoint Javascript
Set Choice Field value»

Here is a code snippet to get a querystring value from the url, say from any listform and populate the»

Recent Forum Posts

Linq to Sharepoint

by RS on May 18, 2012

comments on the code

by spbsmile on May 18, 2012

connection(add) EditControlBlock and my program

by spbsmile on May 18, 2012

Custom master pages used in multiple SharePoint 2010 sites

by ubersteve on May 18, 2012

upload file and click on button but cant upload file into list by using below code

by santhoshreddy on May 18, 2012