How to edit an old version in Google Appsscripts - google-apps-script

I was looking info related to deployment and edit of different versions in new Google AppsScript editor.
https://developers.google.com/apps-script/concepts/deployments#edit_a_versioned_deployment
I noticed that you can "edit and deploy" older versions but when I do that I noticed that the scripts doesn't change.
Before changes
After changes
Here I update the version.
Then I try to edit the old one.
But the script doesn't change, I mean, at this part I would expect to see what I wrote in the first image.
What am I doing wrong?

Editing a versioned deployment doesn't change the current script code. It just changes that deployment code, so you can use it as an add-on, a web app, or what have you, but it doesn't revert your current code to that version.
The old editor did have the functionality you are looking for (clicking File > See verstion history > Restore), but not the new one. There's a feature request in Issue Tracker to add this to the new editor, consider subscribing to it:
Restore an old version in Google Apps Script's new editor

Related

In AppScript, for Workspace Published Add-On Sheet Extensions, how do I switch to Head version and stop Deploying every bug fix?

Each time I fix a bug I have to Deploy and update the Version
in the
console.cloud.google.com
I'm 17 Versions in and I don't think this is how it's supposed to work.
How do I switch back to Head so that I just Save the new code, reload my sheet, and work with the updated code?
I am the admin for the account, so I had published the Extension as an Add-On in the Marketplace so people on the team could see the Extension.
You can Test the add-on directly via 'Run' menu - 'Test as add-on' option.
Select the version on which you want to test and select the document.
Step 1
Step 2

Trying to update Google Sheets Addon

I am trying to update a Google Sheets Addon.
I currently face 2 problems:
the new Script Editor does not know anything about versions (so I used the legacy editor and created a new version there)
when I want to deploy the changes (via the G Suite Marketplace SDK) I get an "Project Key is not associated with the current project or the script version doesn't exist." error when I enter the new version.
What should I do?
We have just rolled back to a previous version, can you refresh and try again? Please let me know how it goes.

App script web change version for each deploy

I created a web app for my google sheet script.
I deployed it with version 1 and and it works
Now I want to make on going changes and deploy my changes,
Do I need to increase the version for each change I deploy? or can I update on current version?
Also, is there a way to get the current version programmaticaly?
For your situation, I would like to introduce because I had a workaround that I also use.
For question 1 :
In generally, when the script of Web Apps was updated, the project version is required to be increased and Web Apps is redeployed with the new version.
But if you want to deploy Web Apps without increasing the version, as a workaround, you can achieve it by using a library. The flow of for this workaround is as follows.
Create 2 projects.
One is the project that Web Apps is deployed.
It supposes that this is the project that you are using now.
Another project is used as a library. Please create this as a standalone project.
Please create a version.
On script editor
File -> Manage versions...
After input description, please click "Save new version".
Please copy this script ID. This is used for installing the library.
For the project that Web Apps is deployed.
Please install the library project as a library.
On script editor
Resources -> Libraries...
For "Add a library", please input the file ID of library project.
Turn on "Development mode".
Set the version to the saved version.
In this sample, please set "Identifier" to "lib".
Please copy and paste the following function. In this project, the script is only this. And please save the project after copy and paste it.
function doGet(e) {return lib.main(e)}
Please deploy Web Apps as a new version.
After this setting, you are not required to modify this project.
For the project which is used as a library.
Please copy and paste the following function.
function main(e) {return yourfunction(e)}
yourfunction(e) is the function in the project that you are using.
In this workaround, when you want to modify the script, please modify the library project. By this, when the library is updated, the project which deployed Web Apps is automatically updated because "Development mode" is turned on when the library is installed. This update is also reflected to Web Apps. So the script of Web Apps can be updated without increasing the version.
As a sample, the scripts for both project after making the settings described above are as follows:
For the project that Web Apps is deployed.
function doGet(e) {
return lib.main(e);
}
For the project which is used as a library.
function main(e) {
return yourfunction(e);
}
function yourfunction(e) {
do something: The script which is run when users accessed to Web Apps.
return something
}
For question 2 :
In order to retrieve the current version of the project, you can use Apps Script API. This is also answered by tehhowch. In a recent update, users got to be able to retrieve and create the project versions. By using this, you can achieve this. The required scope is https://www.googleapis.com/auth/script.projects or https://www.googleapis.com/auth/script.projects.readonly.
The endpoint for retrieving the version list is as follows.
GET https://script.googleapis.com/v1/projects/### scriptId ###/versions
If you want to create the new version using script, you can use the following endpont.
POST https://script.googleapis.com/v1/projects/### scriptId ###/versions
Request body is
{
"versionNumber": 3,
"description": "sample description"
}
References :
Web Apps
Libraries
Google Apps Script API
Method: projects.versions.list
If this was not useful for you, I'm sorry.
When creating a web app for apps script, two links are given:
The one ending exec will only load the specified published version of the code.
The one ending dev will load the latest saved code (allowing for testing of code prior to making a new version).
Programmatic control of the deployed version is available via the Apps Script API, and to a Dev environment via clasp.
Getting versions
Creating versions
You need to increase the version for each change, unless you use the "dev" version of the app when it will always display the latest version. This will only be visible when you are logged into your account though.
It's much easier than everyone makes it sound
Go to Deploy:
Click "Manage deployments"
Under Configuration click the edit pencil
Under "Version" click "New Version"
Click "Deploy" it will auto increment the version for you

Releasing a new version of Google add-on

I am working on an add-on for the new Google spreadsheets but I wonder how versions are handled? In the old script gallery, there were versions. Are they working the same in add-ons after the add-on is published?
Also I see an auto generated Help submenu item. How do I generate content for it?
Thanks.
Thanks to #Steve Lieberman answer I see now how to choose on publish and update later the version of the add-on. But in the documentation I can't find an explanation of what will be the effect of updating to a new version on already used copies of the add-on. Will they be automatically updated? Will they receive in some form a notification of the new version?
Thanks.
When you publish your add-on [1], there's an option to select the version of the script that will be used.
Note there's also a version of the Chrome Web Store entry, this can differ from the version of the script.
The source code that is executed will be based on the version of the script that is published to the Chrome Web Store.
[1] https://developers.google.com/apps-script/add-ons/publish#publish_your_add-on
First create a new deployment/version of the script in the script editor.
Then update the script version in the Project's Google Workspace Marketplace SDK page, App Configuration tab (scroll down), then Save it.
Note that the update will take effect immediately when Saved, including for documents that are currently open in a browser.
Debugging: I don't think it's possible to have multiple deployments/versions of a Published Add-On active at the same. You have to do your debugging of the HEAD version in the Add-On's Host document, or in a document that does not have the Add-On installed (you can add the HEAD deployment of the Project as a script library in that case).

Google Sites: creating a site using a custom template, Scripts not being copied

So I created a template for google sites. This template will be used by a system to create sites automatically. The problem is it seems like the new sites all share the same script( and Scriptdb) where I thought scripts would be copied and each site would have their own version of scripts. The problem is now we will exceed the quotas very fast. What I was trying to achieve was create a site with a certain layout but the data for each site would be different(because they all had different scripts). I thought this would work because I used a similar technique for spreadsheets. I created my spreadsheet, added my script to it and then made a copy and shered it with people who wanted to use it. Then I continued working on the original script without modifying the script for the shared spreadsheet.
Is there a work around for this? Is there anything that can be done so that new scripts are created for each site.
Here is the link to the quota page.
Update:
So I copied the template to see if there are any differences in the behaviour. By copying the site instead of using the site as a template I get a copied version of the script. The problem is still there. I saw the data displayed was the same for both the original site(template) and the new site. I went on to look at the script for the copied site and it had all the copied version of the scripts. I went to the script box in the UI and looked at the published URL for the app script and i found that the new site is still using the original scripts and not the copied versions. So I tried to manually change the source app script to the copied version and i got an error "Sorry, the file you have requested does not exist."
So i went into my drive to check if there is a copied version of the original script and there is no copied version but there is no original version either.
Update 2:
Seems like this happens because the newly created scripts are not automatically deployed so google reference the old scripts where by common sense, it should automatically deploy the new scripts and reference the new scripts.