Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Script - how to call a function from a library

I have this code bound to a spreadsheet. I published a standalone google app script as a library, for which I got an ID.

function callActivateNewMember(){
 var scriptId = "<LIBRARY SCRIPT ID>";
 google.script.run({
  'scriptId': scriptId,
  'resource': {
  'function': 'activateNewMember'
 }
})

}

I got an error message upon execution:

ReferenceError: "google" is not defined.

My intention is simply to keep the code of the application using a spreadsheet and limit the code of the spreadsheet to simply call the function from the standalone code.

like image 823
djchrisblue Avatar asked Nov 14 '25 11:11

djchrisblue


1 Answers

To use libraries you import them from the ResourcesTab and then later you call them with normal dot notation.

Go to Resources > Libraries Add a library (this is where you use the script id)

Then you should be ready to go.

In the script use the string that is called "Identifier" in the libraries popup.

LibraryIdentifier.activateNewMember();

You should already be familiar with this idea from logging:

Logger.log("Hi There");
like image 153
J. G. Avatar answered Nov 17 '25 09:11

J. G.