Reputation: 119
I want different users to be able to edit my Google sheet and my scripts.
Based on the answer here I made a script file in Google drive and used it to successfully manipulate data in the Google sheet.
However, I want users to be able to call the script function from within the Google sheet by clicking a button. When I assign the script function name to a button in my sheet, I get "Script function testFunction could not be found" error.
I have attached following script to my button:
function runTest(){
TestScript.testFunction()
}
TestScript is the name of the standalone script project. However, I get "Reference error: TestScript not defined" when I press the button.
Upvotes: 0
Views: 336
Reputation: 2886
In order to use functions from scripts that are not bounded to your Spreadsheet in your Spreadsheet script you should use libraries.
To do so, follow these steps:
In your script that will run the function (i.e the script that is an outsider for your Spreadsheet as it is not bounded) go to the menu bar and select File -> Manage versions and create a new version with the title you want.
Then, in the same script head over to File -> Project Properties and copy the Script ID
.
Go to your Spreadsheet's bounded script (this is the script that has the function that will be triggered by your button) and in the menu bar head over to Resources -> Libraries, insert the Script ID
, select the latest version and give the library a name to be used locally (for example if it is set to Test
you will call its functions using Test.myFunction();
.
Remember to assign your bounded script function to the button in the Sheet.
Upvotes: 1