Created
December 8, 2012 18:25
-
-
Save eirikb/4241236 to your computer and use it in GitHub Desktop.
Refactoring of http://sharepoint.stackexchange.com/q/53484/627
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 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