V
V
Vladimir Zuev2020-07-17 11:39:39
Google Apps Script
Vladimir Zuev, 2020-07-17 11:39:39

How to call a function in the sidebar?

Hello.
How can I call a function from an html page that is in turn inserted into the sidebar's index.html page?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Stoyanov, 2020-07-17
@vladd56

Call google apps script server function?
It's described here as:
https://developers.google.com/apps-script/guides/h...

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

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

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

Note.
google.script.run.doSomething(); - works asynchronously.
The answer can be obtained in A error in.withSuccessHandler(function)
google.script.run
.withSuccessHandler(function ( response ) {
  console.info(response);
})
.withFailureHandler(function ( response ) {
  console.error(response);
})
.doSomething();

This will not work: You
let response = google.script.run.doSomething();
can also use scriptlets:
https://developers.google.com/apps-script/guides/h...
---
Maxim Stoyanov (stomaks), Google Apps Script developer .
g-apps-script.com
stomaks.me

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question