afrologicinsect
afrologicinsect

Reputation: 171

How can I make this work run from the Client Side

I have exhausted all possible permutations I could possibly try, like moving all of the .js code into the html, but the functions would not run from the doc' sidebar, in every run -click any of those buttons- I have to go back to the script's editor to run the sidebar. The script for functions I embedded in my html is:

function Check() {
  google.script.run.results_run();
}

function Clear() {
  google.script.run.results_clear();
}
<button type="button" class="c-btn c-btn--primary" onclick="javascript:Check();"> Check </button> 
<a class="clear-highlights" onclick="javascript:Clear();">Clear highlights</a>

Doc's AddOn

Upvotes: 1

Views: 149

Answers (1)

Wicket
Wicket

Reputation: 38140

  1. Remove javascript: from onclick="javascript:Check();" and from onclick="javascript:Clear();" as it's not needed. Better if you use an event listener instead of inline JavaScript.
  2. When using google.script.run use withSuccessHandler and withFailureHandler .
function Check() {
  google.script.run
  .withSuccessHandler(function(){
    // if needed do something  when the server side function runs succesfully
  })
  .withFailureHandler(function(error){
    // if an error occurss on server side log the error into the console
    console.error(error.message,error.stack);
    
  }).results_run();
}

function Clear() {
  google.script.run
  .withSuccessHandler(function(){
    // if needed do something  when the server side function runs succesfully
  })
  .withFailureHandler(function(error){
    // if an error occurss on server side log the error into the console
    console.error(error.message,error.stack);
    
  }).results_clear();
}

  1. Review the script execution page, there might be logged a server-side error.

  2. Try disabling the new runtime (Chrome V8)

Resources

Related

Upvotes: 1

Related Questions