Monday, August 24, 2015

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.load(currentUser);
ctx.executeQueryAsync(onSuccess, onFailure);
}

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

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

</script>

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



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...