-
I’m integrating my Google Apps Script library into another guest Google Apps Script.
-
Both the library and the guest script are tied-to Google Sheets.
-
The library has a
sidebar.html
file, which is called into the guest script like this:Guest Script > Script.gs
function onOpen() { SpreadsheetApp.getUi() .createMenu('My Menu') .addItem('Open Sidebar', 'showSidebar') .addToUi(); } function showSidebar() { myLibrary.showSidebar(); }
This works and creates the UI menu, and clicking it opens the
sidebar.html
from the library, which runs as an HTML file with all front-end JavaScript<script>
s inside of it. -
In the
sidebar.html
file (in the library) I have a JavaScript function to communicate with a server-side function throughgoogle.script.run
, like this:Library > sidebar.html
<script> google.script.run .withSuccessHandler((backendResponse) => { console.log('Successfully got backend response!'); }) .withFailureHandler((error) => { console.log('Error getting backend response!'); }) .myBackendFunctionName(someArgument); </script>
This works alright when I run it in a Google Apps Script directly, but, when I run it from an integrated library, it throws the following error to the guest’s console:
Uncaught TypeError:
google.script.run.withSuccessHandler(…).withFailureHandler(…).myBackendFunctionName
is not a function
What am I doing wrong? and how can I fix that?