Created
October 18, 2013 07:00
-
-
Save teeaich/7037532 to your computer and use it in GitHub Desktop.
sharepoint csom get user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var context; | |
var web; | |
var user; | |
// This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model | |
$(document).ready(function () { | |
context = SP.ClientContext.get_current(); | |
web = context.get_web(); | |
getUserName(); | |
}); | |
// This function prepares, loads, and then executes a SharePoint query to get the current users information | |
function getUserName() { | |
user = web.get_currentUser(); | |
context.load(user); | |
context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail); | |
} | |
// This function is executed if the above OM call is successful | |
// It replaces the contents of the 'helloString' element with the user name | |
function onGetUserNameSuccess() { | |
$('#message').text('Hello ' + user.get_title()); | |
} | |
// This function is executed if the above call fails | |
function onGetUserNameFail(sender, args) { | |
alert('Failed to get user name. Error:' + args.get_message()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment