user882670
user882670

Reputation:

Close HTML page after calling server side function in a Google Sheet script

In a GAS for a sheet, I have the following function being executed when the user clicks a button on a HTML page:

function validar(){
   try{
     if($('#demo:checked').val()){
       var demo=1;
     } else {
       var demo=0;
     }
google.script.run.showSidebar(demo).withSuccessHandler(google.script.host.close);
   } catch(e){
     alert('Error: '+e.message);
   }
};

The variable demo is defined by a tick box of that page (wether it is checked or not).

Now, when the function above is executed, I get the alert:

"Error: Cannot read property withSuccessHandler of undefined".

But the server side function showSidebar(demo) is still being called!

Why is the page not being closed? How can I fix this?

Thanks for helping!

Upvotes: 0

Views: 255

Answers (1)

Alan Wells
Alan Wells

Reputation: 31310

Try chaining the withSuccessHandler() before the server function name:

google.script.run
  .withSuccessHandler(google.script.host.close)
  .showSidebar(demo);

Upvotes: 1

Related Questions