1

This is driving me nuts. I've written a html page for my Google web app which has functions written in a .gs file. All I am trying to do is call the functions from the .gs file from the .html file. However, every method I have tried does not seem to work. I know my functions work because they work when I run just them. I am missing how to connect the .gs file to the .html file.

my .gs file looks something like this:

function doGet() {

  return HtmlService.createHtmlOutputFromFile('index');
}

function test()
{
  //getFormattedSpreadsheet("1xPDJJfCqWb2igug3NCFmJJ5nO49U6CK8mLwtaD727AY", "17qcsYh8M-cOwTg9K7sqqnKm0pGgEo6r7x1PguRf9Jk8", "Select School");
  archiveSheet("1wTNing5LAOYHbscQ_DTktIxvWcyc6gw6ZNTvAJDtkTo", "1ugNP0Pp97tnRKHLHa50j-QKx-4ynCfg3zHxtJTayiVk");

}

I need the function to be called on a button click, I tried things like (or even without the google.script.run portion):

<button onclick="google.script.run(test())">Full</button>

but I can't get my button to actually call scripts. I've read you can call scripts to run by just putting them in function() tags as well, but I need this to run on click rather than on load. Perhaps I just don't understand the link between the .gs and .html file. They are seperate files, but within the same Google web app project.

1 Answer 1

5

Your syntax is just slightly wrong. You have:

<button onclick="google.script.run(test())">Full</button>

Should be:

<button onclick="google.script.run.test()">Full</button>

You had a parenthesis where there should be a dot.

Google Documentation - Google Script Run API

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

1 Comment

I'm frustrated that I completely missed that after hours of searching. I'm very very thankful that you saw it. Just tested this, and it works like a charm! Thanks so much!

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.