kwizcom banner advertisement

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>
Get Current User Account Name, E-Mail using Javascript Client Object Model in SharePoint 2013 Get Current User Account Name, E-Mail using Javascript Client Object Model in SharePoint 2013 Reviewed by Salaudeen Rajack on August 24, 2015 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.