0

Here is my code for show a sidebar. When click at OK button, I will insert a new record to my sheet. It works well when I disable V8 by Run->Disable new App Script .. V8. When I enable V8, onClicked in Code.gs not fired anymore. I have checked the V8 Runtime Overview but I didn't find anything.

Index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <button onclick="okClicked()"> OK </button>
    <button onclick="close()">Close </button>
    <script>
      function okClicked(){
          window.alert("A");
          google.script.run.okClicked();
      }
      
      function close(){
          google.script.host.close();
      }
    </script>
  </body>
</html>

Code.gs

function showSidebar() {
  var html = HtmlService.createHtmlOutputFromFile('Index')
      .setTitle('My custom sidebar')
      .setWidth(300);
  SpreadsheetApp.getUi().showSidebar(html);
}

function okClicked(){
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data");
  sheet.appendRow(["A", "B"]);
}

Any help or suggestion would be great appreciated.

Marios
  • 26,333
  • 8
  • 32
  • 52
Linh
  • 57,942
  • 23
  • 262
  • 279
  • 1
    Read [mcve]- specifically describe the problem/error and not your inference of the error/problem. Like: *"when I click the button , nothing happens. I added `console.log("Triggered")` inside `code.gs`, but nothing is logged on the "server console". On the client side, The following error is shown on the "browser console", when I click the button: .... "* – TheMaster Feb 28 '20 at 10:31
  • 1
    Unfortunaty, the code works for me great! Please, check that the book contains the 'Data' sheet. – contributorpw Feb 28 '20 at 11:56
  • What does the execution log show? Does it show a call to `okClicked`? If so, any error? – IMTheNachoMan Feb 28 '20 at 15:14
  • Also, how is `showSidebar` being called? – IMTheNachoMan Feb 28 '20 at 15:15
  • @contributorpw yes, I have 'Data' sheet, when I disable v8, everything working well – Linh Mar 02 '20 at 01:21
  • @IMTheNachoMan I run `showSidebar` by select this function -> then I click `Run` button. there is no error log display – Linh Mar 02 '20 at 01:22

2 Answers2

3

Someone posted an issue similar to createHtmlOutputFromFile and V8 on Google's Issue Tracker. You can check if this issue is adequate for your case and hit the Star to let them know you have the same issue.

If you believe that this issue does not correspond with yours, you can also create a new issue with your case there.

Kessy
  • 1,894
  • 1
  • 8
  • 15
  • This might be more related to the issue you already linked here https://stackoverflow.com/q/60412319 https://issuetracker.google.com/issues/150247026 – TheMaster Mar 02 '20 at 14:28
  • Thank you. I will follow the issue tracker – Linh Mar 06 '20 at 02:04
0

2021 Answer

FWIW, I found that Google Apps Script was erroring out like this when my partner and I were both logged into the same Google account.

We also found that this can happen when new features have been built into your Google Apps Script / Sheets backend code that require updated permissions that haven't been granted yet. It's a bit hacky, but I fixed this by:

  1. Sharing the sheet with another account I own
  2. Logging into that account, then trying to run the function
  3. Agreeing to grant the permissions asked by Google Auth / Scopes in the dialog that follows
Dharman
  • 30,962
  • 25
  • 85
  • 135
Davis Jones
  • 1,504
  • 3
  • 17
  • 25