Skip to content Skip to sidebar Skip to footer

Google.script.run Does Not Work From Html Template

Hi all and thank you for your help in advance. Here is my problem: I am developing spreadsheet tools from a library, through an HTML template, but the server functions do not work

Solution 1:

Where is your script? You need to include the google.script.run inside a script in the HTML.

Info hereAnd here

Try something like this:

Code.gs

function doGet() {
  return HtmlService.createHtmlOutputFromFile('index');
}

function Cancel_Version2(){
  var ui = SpreadsheetApp.getUi();
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  ss.deleteActiveSheet();
}

index.html

<?!= include('CSS'); ?><formstyle="font-size: 22px; font-family: 'calibri'; "><?!= data; ?><br><br><inputtype="button"value="ACCEPT"onclick="deleteSheet()"/><inputtype="button"value="CANCEL"onclick="google.script.host.close();"/></form><script>functiondeleteSheet() {
    google.script.run.Cancel_Version2()
  }
</script>

You can also run it with a success or failure handler to get a call back function. Where onSuccess() & onFailure() would be response functions of the first function you are calling.

<script>functiononSuccess() {
  //create onSuccess response function
}

functiononFailure() {
  //create onFailure response function
}

functiondeleteSheet() { 
  google.script.run.withSuccessHandler(onSuccess).withFailureHandler(onFailure).Cancel_Version2()
}
</script>

Post a Comment for "Google.script.run Does Not Work From Html Template"