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?

8

2 Answers 2

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

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

Comments

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

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.