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 here
And 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'); ?>

<form style="font-size: 22px; font-family: 'calibri'; ">
<?!= data; ?>
<br>
<br>
<input type="button" value="ACCEPT" onclick="deleteSheet()"/>
<input type="button" value="CANCEL" onclick="google.script.host.close();"/>
</form> 

<script>
  function deleteSheet() {
    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>
function onSuccess() {
  //create onSuccess response function
}

function onFailure() {
  //create onFailure response function
}

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

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