5

Trying to figure out Google Apps Script for making Google docs addons. I have:

Code.gs

function helloWorld() {
    return "Hello World";
}  

under code.gs which I call in:

Sidebar.html

console.log("This should say Hello World: " + google.script.run.helloWorld()) 

It returns:

This should say Hello World: undefined  

What is the obvious thing I am missing?

1 Answer 1

5

google.script.run won't return a value like you'd expect a usual Apps Script function to. Instead, you should use .withSuccessHandler(functionToRun)

Like this:

    google.script.run
        .withSuccessHandler(functionToRun)
        .helloWorld();

    function functionToRun(argument) {
        console.log("This should say Hello World: " + argument);
    }

In this example, the server-side Apps Script function helloWorld will run the client-side function functionToRun() and pass the result of helloWorld() as an argument.

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

1 Comment

I think I understand. It might take a little bit to click but my code is working now thank you!

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.