How to get Login User Name /Email in SharePoint Online or SharePoint 2013/2016 using JSOM?

Hello SharePointers,

In this blog, we will see piece of codeĀ get Login User Name /Email in SharePoint Online or SharePoint 2013/2016 using JSOM?

<script type=”text/ecmascript”>
ExecuteOrDelayUntilScriptLoaded(getUser, “sp.js”);
function getUser(){
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());
alert(currentUser.get_email());
}
function onFailure() {
alert(‘request failed’ + args.get_message() + ‘\n’ + args.get_stackTrace());
}
</script>

Happy SharePointing Folks.

Leave a Reply

Your email address will not be published. Required fields are marked *