.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Code Snippets >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Get the Current Logged User name in sharepoint using JSON

Posted By:Sagar Pardeshi       Posted Date: April 30, 2014    Points: 40    Category: SharePoint    URL: http://www.dotnetspark.com  

Get the Current Logged User name in sharepoint using JSON

<script src="/Style Library/scripts/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () { 

var currentUser;
// Ensure that the SP.js is loaded
if (SP.ClientContext != null) {
  SP.SOD.executeOrDelayUntilScriptLoaded(getCurrentUser, 'SP.js');
else {
  SP.SOD.executeFunc('sp.js', null, getCurrentUser);
function getCurrentUser() {
   context = new SP.ClientContext.get_current();
    web = context.get_web();
  currentUser = web.get_currentUser();
  context.executeQueryAsync(onSuccessMethod, onRequestFail);

function onSuccessMethod(sender, args) {
  var account = currentUser.get_loginName();
  var title = currentUser.get_title();
  currentUserAccount = account.substring(account.indexOf("|") + 1);

// This function runs if the executeQueryAsync call fails.
function onRequestFail(sender, args) {
 // alert('request failed' + args.get_message() + '\n' + args.get_stackTrace());



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend