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.

6
  • 1
    Read minimal reproducible example- 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: .... " Commented Feb 28, 2020 at 10:31
  • 1
    Unfortunaty, the code works for me great! Please, check that the book contains the 'Data' sheet. Commented Feb 28, 2020 at 11:56
  • What does the execution log show? Does it show a call to okClicked? If so, any error? Commented Feb 28, 2020 at 15:14
  • Also, how is showSidebar being called? Commented Feb 28, 2020 at 15:15
  • @contributorpw yes, I have 'Data' sheet, when I disable v8, everything working well Commented Mar 2, 2020 at 1:21

2 Answers 2

3
+50

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This might be more related to the issue you already linked here stackoverflow.com/q/60412319 issuetracker.google.com/issues/150247026
Thank you. I will follow the issue tracker
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.