How to run standalone script from google sheet - google-apps-script

I had a google sheet with bounded script that was working fine but needed to be run with standalone script so that other people can use it. I made a copy of the spreadsheet then cut out all the bounded script and past into a standalone script. I have turned one the sheet and task api in the standalone sheet and saved the version.
Then I went to the bounded script and included the unbounded script as a library.
What else do I have to do to see and use the codes in the library.

Related

When running a google app script on a google sheets, does it run one app script file, or can it run more than one file?

My plan is to link a google app script to my google sheets. I have 16 tabs on my google sheets. I want to make 16 app script files inside the same app script project. I also want to set time trigger on each app script to run at a certain time. My question is will every file inside the app script file will run, or only one app script will run?
The output I am looking for is that I do not have to press any button on the sheets or the app script. I want it to run each app script file at a certain time, and for the google sheets to update at that time. Each google sheet tab should update at the time they are assigned in the app script. How can I make this happen?
Thanks in advance.
Every scripts are runnable, unless the function names do not duplicate.
A project is similar to a html file, while each script file is included by <script src="name.js">
However, I doubt whether you really need one script file, or even a function for each sheet.
Of course, it depends on what you want to do. But I guess the works are similar and they could be combined into one or a few functions.

Can I link a script to a google sheets which already has a script?

I have a google sheets which is linked to a form and a google scripts that was created in the menu of google sheets. This script runs fine and I use it to format the data. However, I have another script which I created from the google developer console, which sends and receives data from a website. I need this second script to get the value of a cell in the google sheets.
How can I link this second form to the google sheets while keeping the script already linked to the sheets?
When looking at responses to other questions they seem to be about individual sheets in a set so just to clarify, when referring to google sheets I mean the whole google sheets document. I only have one sheet anyways.
If it helps: The script I want to add acts a bit like a server and is being deployed by google scripts while the script that is already linked is only run when I call it on the sheets.
There is not way of attaching a standalone script to a document making it a bound script (which is the actual terminology for the script linked the the document).
The simplest way would be to copy-paste the code to the other script. You can deploy the bounded script.
If you really need more than one project for whatever reason, you can enable the Apps Script API and use projects.create (read reference) to create another one. If you don't know what this means, you probably shouldn't use it as it's finicky at best.
I found a solution which was to link the script to the google sheets using
var ss = SpreadsheetApp.openById("SHEET_ID_HERE");
I can then use ss.getActiveSheet().getRange().getValue();
and other funtions.
Thanks for the help!

Google Apps Script How to access script from spreadsheet

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.
Issue:
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.
Use libraries:
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:
Visit the standalone script (project called STANDALONE in this example) where you have your desired function:
function standaloneFunction() {
// Do some stuff
}
Create a version of your script: see Creating a version.
Click File > Project Properties and copy the Project key: see Sharing a library.
Visit the script bound to your spreadsheet.
Include the library in your bound script by clicking 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.
Choose the function Identifier and the script Version:
You can now call the standalone function in your bound script, using the Identifier:
function boundFunction() {
STANDALONE.standaloneFunction();
}
And finally you can assign boundFunction to your clickable image.
Reference:
Clickable images and drawings in Google Sheets
Libraries

Multiple files in Google App Script My Project

I'm new to this google script thing so I'm not sure what should I do with this. So, I'm working with 8 folders with files with the same structure and scripts. So, when I opened my projects on the Google App Script. I currently have 178 projects. I just want to ask if the picture below is a normal thing or is there a way for me to minimize it since some of it has the same scripts? Can I use one project in multiple sheets?
As you can see in the picture below, I do have 8 ARCS_AP_ROWS since I duplicate the spreadsheet 8 times. The scripts in there were all the same.
The reason you are having a separate script for each spreadsheet is because you created container-bound scripts.
What are container-bound scripts?
According to the Apps Script documentation:
A script is bound to a Google Sheets, Docs, Slides, or Forms file if it was created from that document rather than as a standalone script. The file a bound script is attached to is referred to as a "container". Bound scripts generally behave like standalone scripts except that they do not appear in Google Drive, they cannot be detached from the file they are bound to, and they gain a few special privileges over the parent file.
TL;DR - they're scripts created for one particular document.
So even though you essentially have the same script, the document on which the script acts is different.
What you can do
Create a standalone script and use SpreadsheetApp.openById("SPREADSHEET_ID") and pass the SPREADSHEET_ID parameter in order to open a specific spreadsheet;
Create an add-on.
Reference
Container-bound Scripts;
Standalone Scripts;
Apps Script SpreadsheetApp Class - openById(id);
Google Workspace Add-ons.

bound standalone google app script to google sheet

I created a google app script that is bound to google sheet later I moved it as standalone script inside a google drive folder. I thought I will be able to reuse it across multiple sheet. Now I am not able to find any way to run standalone script inside my google sheets. Please suggest.
From your standalone script you can access your spreadsheets and work this way with your files.
Use something like this to get a set of spreadsheets (pseudocode)
var ssList = ['...','...']
for each element in ssList do:
SpreadsheetApp.openById(ssList[element]);
Then you can reuse your code and access multiple spreadsheets.
But it is not possible to access multiple apps script files, only one file is bound to your spreadsheet.