2

I am trying to use the google.run.script function in one of my projects and it doesn't seem to be triggering the function to run.

So I made a new project and tested a simple example, copied exactly from https://developers.google.com/apps-script/guides/html/reference/run.

Code.gs

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

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

Index.html

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

However when I run the doGet() function then check my logs I do not see the 'I was called', and I cannot figure out how to correctly use google.run.script so I can use it in another project.

Kyle
  • 89
  • 2
  • 13
  • Do you get anything in the debugger console in your browser? And are you sure you are connecting to the proper server? There doesn't seem to be anything wrong with your code. – TinkerTenorSoftwareGuy Oct 12 '17 at 19:48
  • How do I view the debugger console and check the server connection? The debug option in scripts won't let me click it and I only know how to check the Logs and execution log. There is nothing in the Log, which their should be and the execution log shows the html as getting set up and run it seems. – Kyle Oct 12 '17 at 20:21
  • https://stackoverflow.com/questions/66420/how-do-you-launch-the-javascript-debugger-in-google-chrome – TinkerTenorSoftwareGuy Oct 12 '17 at 22:00
  • Did you manage to solve it? I am facing the same issue. – Mukesh Ghatiya Jun 11 '20 at 00:21

2 Answers2

1

I think that your script works fine. doSomething() is run by google.script.run.doSomething(), and you can see I was called! at the log. So please confirm the following flow.

  1. About deploying Web Apps. Even if doGet() is directly run on script editor, it doesn't work. At that time, please deploy as Web Apps. You can see the detail of how to deploy Web Apps is here.
  2. After the script is modified, project version has to be updated. By this, the latest script can be used by Web Apps. If you don't want to update the project version, you can use the latest script by clicking latest code of Test web app for your latest code.. This can be seen below.
    • On script editor
    • Publish -> Deploy as web app
    • You can see "Test web app for your latest code." at "Current web app URL:"

If this was not useful for you, I'm sorry.

Tanaike
  • 181,128
  • 11
  • 97
  • 165
0

I just copied your code and it is working for me. It seems that you have other code in your project which might have some errors.

Otherwise, you might be using URL of old version of your deployed project.

Deployment procedure is available here. https://developers.google.com/apps-script/guides/web

  • I am having same issue. I even created a fresh project with just this and still having problem. The function is not getting invoked. – Mukesh Ghatiya Jun 11 '20 at 00:22