Is there a way to restore previous Google Apps Script Editor Versions - google-apps-script

Is there a way to restore previous Google Apps Script Editor Versions?
I accidentally deleted a big portion of my code in the Google Script Editor. In the new editor, I do not see a way to restore versions.
In the old editor, I can go to File > See version history (please see image).
Unfortunately, this only goes back a few hours.
Is there a way to retrieve a version from yesterday?
TIA

You can try reverting to the legacy editor to access your script revision by clicking on the "Use legacy editor" button on the top right of the Apps Script window.

Even if you weren't already using clasp, when you created those versions, you can still use it now to retrieve the code for them. However, this only works if you created an explicit version of the code, under deployments, even if you didn't actually deploy them.
First install NPM, then:
npm i #google/clasp -g # install clasp
clasp login # login to your Google account
mkdir some_folder
cd some_folder
clasp clone <ScriptId> # replace <ScriptID> with your script id
clasp pull --versionNumber X # replace X with version number you want

Related

Error working with google apps script locally in VSCode using CLASP and push command

I have cloned a google apps script project but when trying to deploy the changes with the push command I get the following error:
PS D:\evcPRD> clasp push
No valid D:\evcPRD.clasp.json project file. You may need to create or clone a project first.
Any idea how to solve this?
Thank you

Google Apps Script: "Error 401: deleted_client The OAuth client was deleted" All of a sudden?

I currently use a Google App Scripts on Google Sheets for my budgeting spreadsheet. Essentially, the way I have it set up is:
Buy item
Input expense onto Google form (which feeds into a spreadsheet)
Use Apps scripts to convert timestamp into yyyy-MM-dd
I've been using this process for 4 years but all of a sudden, today it stopped working by giving me this error below.
Error 401: deleted_client The OAuth client was deleted
Here's my app script:
Here's my trigger:
At some point your Apps Script project's attached Google Cloud Platform (GCP) project (which manages the Oauth client) was likely deleted. You could confirm this by going to the Apps Script project editor, click the gear on the left for Project Settings, then click the Project Number link in the Google Cloud Platform (GCP) Project section. If it loads the GCP console (using the correct Google account) but gives you an error instead of bringing you to the project, then it probably doesn't exist anymore.
First, check if it's been deleted within the past 30 days and could be recovered:
In the GCP console, go to the Manage resources page (project picker → three dots button → select your organization → Manage resources).
Below the list of organizations, folders, and projects, click Resources pending deletion.
If you see the project there, check the box then click Restore. In the dialog that appears, confirm that you want to restore the project.
Go back to the Apps Script project editor and run one of your functions, and it should allow you to authorize the project again instead of giving you the 401 error.
If the project does not appear in the Resources pending deletion list because it'd been deleted over 30 days ago:
Copy all of your Apps Script projects' files to your local machine. If there are many files, consider using the clasp CLI tool, which would allow you to clone the entire project locally with one clasp pull command.
[IMPORTANT] Confirm that all of the files have been stored locally (and backed up, if desired), because the Apps Script project will be deleted permanently.
Make note of any services which are enabled in the Services section of the Apps Script project editor sidebar.
Delete the Apps Script project by going to the Apps Script project's Overview page, then click the trash can labeled Delete project forever.
In your Google Sheets doc, go to Extensions → Apps Script again and it will create a new Apps Script project (with attached GCP project).
Save the default Code.gs file
Re-create the projects' files. If you'd used clasp pull in the first step, then you can use clasp push to push the files from your local machine back to the project. In this case, go to the Apps Script project's Project Settings page and copy the Script ID. Then update the scriptId in the local .clasp.json file, save it, then clasp push.
If there were Services enabled in the previous project, enable them again in the Services section of the editor sidebar.
Run one of your functions and it should allow you to authorize the project again instead of giving you the 401 error.

Not able to push files using clasp push command

I am able to get the files using clasp pull command but not able to update the files using clasp push command. It says "No files to push".
When I run command clasp status then it shows all of my project files in "Ignore files". Previously it was working completely and the problem occurred yesterday when I changed my laptop.
I also tried making .claspignore file and it also did not work.
For reference, please see the screenshot.
Please help.
I think for me I found the issue after using trying
clasp version "YOUR_VERSION_STRING".
I got a console message to enable API access. Once I enabled that I was able to make pushes. It's funny because I was able to clone and pull just fine.
So this is the Settings URL and then make sure that "Google Apps Script API Access" is on.

Clasp Could not read API credentials. Are you logged in globally?

I'm logging in with clasp login --creds <file> which produces a local .clasprc.json file.
It says that I am logged in, but when I run another command I get:
Could not read API credentials. Are you logged in globally?
Any thoughts on why its not looking at my local clasprc file first?
Currently using version clasp v. 2.2.0
I ran into the same problem on Windows 10 and found that you need to login both globally and locally to use clasp run. There should be a .clasprc.json file in both your project folder and user folder.
I think I have finally found the solution for the same problem
Follow along with the comments from this github issue
Add the "oauthScopes" field to your local code and push it to your app
If you can't push, then copy-paste it to manifest file in the browser
Then you have to publish the app, and there were few things I've done, not sure which one helped. In the app in browser:
add the app version in File->Manage Versions
Publish -> Deploy as API executable
try to login with clasp and creds.json file
try to run something clasp run testRun
it may show the error that you're missing some oauth permissions, but it will list which ones, and you can add them
In my case, one weird thing that also helped was to enable some Google API
so in the app in browser: Resources -> Advanced Google Services -> enable some API
then try to do clasp run
if it works, you can disable the API that you have enabled previously.
Hope that helps

Install TortoiseHG on a shared drive?

Would it be possible to put install THG on a shared drive and let
users run it from there without having to install it locally on each
user's machine?
I'd be willing to accept some minor loss of functionality such as no
overlay icons or menus in Explorer. Maybe people can only use the
workbench interface...
Bonus points if the local stuff could be wired up after it was
installed centrally!
I got an answer from the TortoiseHG mailing list:
There are two things you miss by not running the installer:
Explorer extension (context menu, overlay icons)
Having the apps in your PATH (thg.exe, hg.exe, kdiff.exe, tortoiseplink.exe)
The workbench and other apps should run just fine from a copy of the
install folder.
--
Steve Borho
Okay, my "initial reactions" aside, you might be able to copy the TortoiseHg folder after installing it to your machine then copying the Program Files directory a network location and run it from there. (At least, it appears to have been possible in the past)
Try copying the Program Files\TortoiseHg directory to the network share (you could use a network drive to make your life in cmd easier)
Then run thg.exe with a shortcut/cmd/Run... prompt:
<network location>\TortoiseHg\thg.exe
Good luck!