How to prevent Apps Script from opening multiple projects? - google-apps-script

I have an html dialog for Sheets (container bound dialog) that is used for input and saving of customer data. I made a copy of it for use in a different office, so now I have Worksheet#1 with Script project "Scripts" and Copy of Worksheet#1 with Script project "Copy of Scripts". We've made changes to Scripts so it is no longer the same as Copy of Scripts.
Sometimes Worksheet#1 triggers scripts that are in Copy of Scripts. Not sure why. On these occasions I can open up script editor and it asks which project to open (Scripts or Copy or Scripts) and once I select the right one it behaves properly until the next time this happens.
How can I insure that it always opens the correct project?

You will see this behavior sometimes if you have multiple projects within a script.
Check whether you have multiple projects in one of those sheets.
File > Open...
Here's a spreadsheet-contained script with two projects in it:
Open the project you want to delete.
Delete it.
File > Delete Project...

Related

Multiple copies of script in Google Apps Script

When I click on Tools -> Script Editor in a Google Doc, I am presented with the following screen, whereas before I would be directed straight to the script editor:
I am worried that there are now two instances of my script. Is there a place I can easily see and manage the scripts and projects in Google Apps Script? I have checked out Google Cloud Platform Project through the script editor menu (Resources -> Cloud Platform project), but the resulting dashboard is not very intuitive to me.
As some background: I was trying to test Google Apps Script code deployment using Clasp and after the test, I wound up with the above issue. I don't know if the issue came about when I used Clasp commands or if it was when I copied the existing document before trying out Clasp.
Thank you for taking the time to read this. Any info is appreciated.
You can bind multiple script projects to a container (the container in this case being your document).
When you have multiple projects bound to a container and you open the script editor, you are provided with a menu with a list of your projects.
You can easily delete the duplicate project. Just select it, and then when you're in the Apps Script GUI editor, navigate to File > Delete Project.
G-Suite Developer Hub
You can access all of your scripts at G-Suite Developer Hub. You can even monitor script performance from there.
Same Named Scripts
You will want to avoid scripts with the same name within a project but it's okay if they are in different projects.
Backups
If you want to make a backup of a project you can just copy it. In the case of a container app you can make a copy of the container and you will be making a copy of the scripts it contains at the same time.

Accessing the script for a Google Sheets spreadsheet

I have a bunch of custom functions for a Google Sheets spreadsheet (access via Tools -> Script Editor...) that were working fine. At some point I decided to back up my functions by saving a copy of the script.
Now when I click Tools -> Script Editor... I get:
Select a project to open
Copy of myspreadsheet
myspreadsheet
Create a new project
The spreadsheet now alternates between the two scripts in an unpredictable fashion, using an old version of the same functions, then switching. How can I designate which one it should use? I can't even work out how to delete one of them.
From https://developers.google.com/apps-script/guides/projects
Deleting a container-bound project
Open your container-bound project using the appropriate method above.
Select File > Delete.
Click Yes to delete the project.

google spreadsheet script editor: delete a project

I have two script projects for a spreadsheet. One was a temp one for development testing. I want to delete the temp one. When I click on script editor it shows both projects, and I can select one, but there is no option for deleting.
Also when I open the project itself there is no delete option.
I have seen other SO threads (such as this), but it seems the interface is changed since then.
Attached the screenshots.
Script Editor File menu:
Make sure that you are the owner of the script.
I've tried to replicate your issue in other scripts which I don't own and it seems that I cannot see a Delete Project... option under File menu.
But with my owned script, there is a Delete Project... option. See screenshot.
Here's a reference post: How can I remove a project from a Google Spreadsheet?
UPDATE (based from OP's comment):
You must be the owner of the spreadsheet to show the Delete Project... option.

How can I remove a project from a Google Spreadsheet?

I made a copy of a Google Apps Script project by mistake by choosing File > Make a copy... on Script Editor and since then every time I click Tools > Script Editor... on the Spreadsheet screen the project belongs to, I see a screen showing the two projects (original one and copied one) and I need to choose one to open the script editor. To be worse, the original script became unexecutable since I made the copy, I don't know if this is the cause of that though.
So, I'd like to remove the copy project from the Spreadsheet. How can I do that? I can't find any menu to remove project.
Thanks,
Open the "copy of" version of the script, click File -> Delete Project... This will generate a confirmation box. Click the Delete button to confirm that you would like to delete the project. This should leave your original as the only associated script.

Backing up Gapps source

I have fallen into the trap of (accidentally) deleting all scripts from the script editor. Lost 3 weeks of work in this lesson. I (maybe) will not do that again, but it raises the question "What is a complete backup solution for Gapps source?"
I, of course, can make a copy of my script either in the editor, or within Google drive. I however question if my (very complex) User interface (built using GUIBilder) is protected. So far, I have been unable to locate the code GUI Builder throws.
Also note it is not possible to download an apps script in GDrive, so how do I get a personal copy of my work product?
=====
To clarify - I know how to copy and paste the source of a script BUT this does not capture the 200 gadget GUI that was built using GUI Builder.
As to the trap door in the editor -- I had several versions of this development -- I highlighted ONE in the left hand list and requested delete (from withing the Google script editor) file/delete -- magic -- ALL SCRIPTS DISAPPEARED. I will never touch the File/Delete menu again.
In some cases, you should be able to get your code back. (EDIT - except, it seems, any script file you delete from within the script editor, and any auto-generated code related to the GUI Builder, or Forms. -- Ouch!)
Your options depend on what you mean by deleting all scripts from the script editor.
If you only deleted the text of your script while in the editor, say by Ctrl-A + del, then you can recover it within the editor. File - See Revision History will bring up a dialog that lets you time-travel back to when your script was intact.
If you deleted the file from Google Drive, then it's in a trash folder, and can be recovered from there. You'll find the Trash folder in the Drive navigation tree.
If you deleted a script "file" from within the editor, you're out of luck until Google fixes Issue 1424: There is no possibility to recover script files/projects.
If you deleted any auto-generated code related to the GUI Builder, or Forms, you can't get them back. (Forms are not included in Restore from Revision History)
If you want to store your scripts some other place, that's a good idea - that will provide additional safety for items 1 to 3, but unfortunately not 4. You will need to copy the text from the editor into another file or online repository (e.g. Github). Get into the habit of including info about Libraries in your comments, because there is no way to back up those resource links.