Reputation: 445
I have written a Google Sheets add-on that uses a modal dialog as the interface. I was having trouble getting the success handler to run, so I created a skeleton interface for testing, and have the same issue.
Whenever the server-side function returns, the function specified in the success handler should run. Instead, it throws an error "Untaught TypeError: a is not a function". I am able to manually trigger the function specified for the handler via a button (added for demonstration purposes only. Code below:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function success(){
document.getElementById("waitMessage").innerHTML = "TEST";
}
function testFunc(){
google.script.run.withSuccessHandler("success").serverSideFunc();
}
</script>
</head>
<body>
<p>
Click the button to close the window
</p>
<form>
//Doesn't work
<input type="button" name="test" value="Server-side test" onclick="testFunc()">
//Works
<input type="button" name="test-client" value="Client-side test" onclick="success()">
</form>
<div id="waitMessage">
<p></p>
</div>
</body>
</html>
.gs script file below:
function serverSideFunc(){
Logger.log("");
}
As you can see, the script file is just a dummy function designed to trigger the success handler.
What's going on here? Have I missed something simple?
Upvotes: 0
Views: 137
Reputation: 3554
You are not having an error returned. You do not put quotes around the function name to run:
function testFunc(){
google.script.run.withSuccessHandler(success).serverSideFunc();
}
Upvotes: 2