How can I get this function to return the value? In all the examples I have seen, folks use an alert
in the delegate functions, but I need to return the value instead. When I call the function, it fetches me my default string, which means the executeQueryAsync
is not setting the variable.
What am I doing wrong?
var thisuser = SPGetSPcurrentUser();
alert(thisuser);
//-------------------------------------------------------------------
var SPGetSPcurrentUser = function(){
var spuserid = "Error";
var context = new SP.ClientContext.get_current();
this.website = context.get_web();
this.currentUser = website.get_currentUser();
context.load(currentUser);
context.executeQueryAsync(
function(sender, args){ this.spuserid = currentUser.get_loginName();},
function(sender, args){ this.spuserid = 'request failed ' + args.get_message() + '\n'+ args.get_stackTrace();}
)
return spuserid;
}