0

I was trying to get add some custom scripts into google Sheets. But got so many problems even after following the ditto steps as given in the guides of GoogleCodeLabs.

that's my code main.gs file

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

function doSomething() {
  Logger.log('I was called!');
}

index.html file

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script>
      google.script.run.doSomething();
    </script>
  </head>
  <body>
  </body>
</html>

appsscript.json file

{
  "timeZone": "Asia/Kolkata",
  "dependencies": {
  },
  "webapp": {
    "access": "MYSELF",
    "executeAs": "USER_DEPLOYING"
  },
  "exceptionLogging": "STACKDRIVER",
  "oauthScopes": ["https://www.googleapis.com/auth/spreadsheets.readonly",
                  "https://www.googleapis.com/auth/userinfo.email",
                  "https://www.googleapis.com/auth/spreadsheets",
                  "https://www.googleapis.com/auth/script.container.ui"],
  "runtimeVersion": "V8"
}

also i am deploying it with every small changes but even after doing the same as mentioned in the guides i couldn't log the output. what am i missing?

Marios
  • 26,333
  • 8
  • 32
  • 52
ME-ON1
  • 83
  • 1
  • 10
  • I don't know for sure but one Index is capitatilized and the other is not. My dialog example is pretty close to the same thing. – Cooper Jun 27 '20 at 21:42
  • 2
    The logger does take a long time to display results in V8 and so I find it quick to use view/executions – Cooper Jun 27 '20 at 22:36
  • What runtime are you using? Whare are you looking for the logs? How long you waited for the logs to appear? – Rubén Jun 27 '20 at 22:41
  • 1
    Related [Very slow “Logs” with Google Apps Script V8 vs Rhino?](https://stackoverflow.com/q/60404784/1595451) – Rubén Jun 27 '20 at 22:46
  • 1
    More related: https://stackoverflow.com/q/61727630/1595451, https://stackoverflow.com/q/60918110/1595451 (no answers yer), https://stackoverflow.com/q/62010980/1595451 – Rubén Jun 27 '20 at 22:53
  • 1
    More related: https://stackoverflow.com/q/59792504/1595451 – Rubén Jun 27 '20 at 22:59
  • 2
    Logs are viewable in script executions. Go to the script dashboard and look at the script execution logs there. – IMTheNachoMan Jun 27 '20 at 23:01

2 Answers2

3

Try this:

function myfun() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  const html='<!DOCTYPE html><html><head><base target="_top"><script>google.script.run.withSuccessHandler(function(){document.getElementById("msg").innerHTML="I did something Useful";}).doSomething();</script></head><body><div id="msg"></div></body></html>';
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html), "Dialog");
}

function doSomething() {
  console.log('something');
  return;
}

enter image description here

enter image description here

Cooper
  • 59,616
  • 6
  • 23
  • 54
1

I ran into this same thing recently on the NEW google apps script editor.

the Logger.log will not show anything on the "Execution Log" in the editor unless you execute the function from the editor itself.

but,

if the function that has the Logger.log is executed with google.script.run (client side), You WILL see whatever was logged with Logger.log in "Executions"

enter image description here

Dharman
  • 30,962
  • 25
  • 85
  • 135
Francisco Cortes
  • 1,121
  • 10
  • 19