title: Google Apps Script HTML Service: Passing variables
body: <p>I have a simple function that retrieves the session user email and returns it. I would like to run this function and return this value when I click a button in my html service template. Unfortunately it is always undefined. Below is a short snipped of what I am trying to do.</p>
  
  <pre><code>//code.gs
  function getUser(){
  
  var user = Session.getActiveUser().getEmail();  
  Logger.log('User was called')
  return user;
  
  }
  
  //Page.html
   &lt;p&gt;Your username: &lt;?= user ?&gt; &lt;/p&gt; \\this works ok. 
  
   &lt;button type="button" onclick="subMe()"id="submit" &gt;Submit&lt;/button&gt;
  
  &lt;script&gt;
  function subMe(){
  var user = google.script.run.getUser(); //Logger works but no return value!
  
  }
  
   function setUser(activeUser){
     alert(activeUser);
     return activeUser;
   }
  
   google.script.run.withSuccessHandler(setUser).getUser(); //alert works OK, but no return value
  </code></pre>
  
  <p>So in the end I want to call this function and return the session user and have that stored in a variable so I can use it later. Any tips appreciated!</p>
  
  <p>Regards</p>
  
  <p>Shawn</p>