Reputation: 289
The variable 'user' is not assigned the users email, and the label 'QT's text is not changed. Is this the correct way to call this function.
$(document).ready( function (){
var user = google.script.run.getCurrentUser();
$('#masterDiv').data('cUser', user);
$('#QT').text(user);
});
//Server function
function getCurrentUser() {
var userEmail = Session.getActiveUser().getEmail();
return userEmail;
}
Upvotes: 1
Views: 64
Reputation: 3778
Almost, you must include a withSuccessHandler
, since google.script.run
calls are asynchronous Javascript doens't wait for it to return something to continue the code, here:
$(document).ready( function (){
var user = google.script.run.withSuccessHandler(whatToDo).getCurrentUser();
});
function whatToDo( returnedFromServer ){
$('#masterDiv').data('cUser', returnedFromServer);
$('#QT').text(user);
}
Upvotes: 1