public
Created

  • Download Gist
SPGetSPcurrentUser.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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);
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.