Skip to content

Instantly share code, notes, and snippets.

@eirikb
Created December 8, 2012 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eirikb/4241236 to your computer and use it in GitHub Desktop.
Save eirikb/4241236 to your computer and use it in GitHub Desktop.
var SPGetSPcurrentUser = function(callback) {
var spuserid = "Error";
var context = new SP.ClientContext.get_current();
// Using this here would make it global, as the function is not called with 'new'
// and this would then point to the global object, window
//this.website = context.get_web();
var website = context.get_web();
var currentUser = website.get_currentUser();
context.load(currentUser);
context.executeQueryAsync(
function(sender, args) {
callback(currentUser.get_loginName());
}, function(sender, args) {
this.spuserid = 'request failed ' + args.get_message() + '\n' + args.get_stackTrace();
});
};
var thisuser = SPGetSPcurrentUser(function(thisuser) {
alert(thisuser);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment