I have written a Google Apps Script script using the Apps Script App in Google Suite. I also created a spreadsheet using the same account. I want to add a button to my spreadsheet that runs the script when I click it. I added an image, right clicked, hit three circles and selected the "Assign script" option. Problem: I can only assign scripts that appear under tools>script editor. I cannot assign the script that I previously wrote by opening the Apps Script app directly (in the same account). I can copy paste the whole thing into the spreadsheet's scripts, but then I have to maintain two versions. What I want I want to directly assign the script that I wrote earlier to the button.
Is this possible? Thanks.
Only functions in the script bound to your spreadsheet can be assigned to a clickable image/drawing:
You can also assign an Apps Script function to an image or drawing in Google Sheets, so long as the script is bound to the spreadsheet.
As a workaround, I'd suggest creating a library for your standalone script (so that the script's functions can be reused in other scripts) and call it on the script bound to your spreadsheet.
You can do it the following way:
STANDALONE
in this example) where you have your desired function:function standaloneFunction() {
// Do some stuff
}
File > Project Properties
and copy the Project key
: see Sharing a library.Resources > Libraries
and paste the previous Project key
into the Add a Library
text box: see Gaining access to a library and including it in your project.Identifier
and the script Version
:Identifier
:function boundFunction() {
STANDALONE.standaloneFunction();
}
boundFunction
to your clickable image.