How do I create a User-managed Cloud Platform project? - google-apps-script

I created a script inside a Google Docs document. I want to use it in all my docs documents, so inside the script editor I clicked Publish -> Deploy as Docs add-on...
However, the following alert prompts:
What should I do in order to use my script?

Please check out the instructions that have been documented under:
Google Cloud Platform Projects > Switching to a different standard GCP project.
Sharing the steps here too, for reference:
Create a new Google Cloud Platform (GCP) project - instructions available here if you don't already have one.
in case you already have a GCP project configured, switch to that project via the cloud console.
Get the Project ID/number - instructions available here
Then go back to your script from the Apps Script browser editor and navigate to Resources > Cloud Platform project
In the Change Project section, paste the project number you copied into the text field, then click Set Project & finally Confirm on the subsequent page.
Personally, I had difficulties following through step 2 i.e. getting the project number so here's where you find it -

Related

No Option to Switch Apps Script Project to a new Cloud Platform Project?

I am trying to add existing apps script projects to a standard Cloud Platform Project so that I have more control over the errors and logging. I have no trouble migrating recently created apps script projects to my new Cloud Platform Project, but I can't get older apps script projects to do it.
New apps script projects have it right in the resources menu:
But the older apps script projects completely lack the "Cloud Platform project..." option under resources:
I can't seem to find any documentation on why this is the case, or on how to add older scripts. Can anyone help me here?
Thanks!
If you cannot see the menu Ressources > Cloud Platform project most likely you are not the owner of the script
Either this is the reason, or something else -your best bet is to go on File > Make a copy to create a new Apps Script file.

Cannot switch my Google Script to a new Cloud Platform project "in an Apps Script-managed folder"

I have 2 google scripts using each one google sheet.
My issue is that one of those scripts (older one) benefits from the Google Cloud Error reporting and email notifications which is very helpful whereas the newer one doesn't.
And it looks like this is due to the fact, that since April 2019, when new scripts are created they are, "a default GCP project is also created behind the scenes."
https://tanaikech.github.io/2019/07/05/linking-cloud-platform-project-to-google-apps-script-project/
And indeed, when looking, from the script project side, the Ressource / Cloud Platform project info, I can see that they are not set in the same way:
The older one has clear GCP link visible, whereas the second one (newer) is not showing any project and says instead:
"This script has an Apps Scripts managed Cloud Platform project"
I found this:
cloud platform project dialog box
And understood that I needed to create a new standard Google Cloud project, which I did and now when I try to copy the project number I get this error message:
"You cannot switch to a Cloud Platform project in an Apps Script-managed folder."
So I'm clueless now.
The reason I could not transfer the script to the new project was it was created in the "system-gsuite/apps-script" folder, which is a special folder for the automatic projects created by apps-script. You cannot move scripts from one automatic project to another automatic project.
I moved my new project out to a "normal" folder and everything worked.
To move a Google Cloud Platform project from one folder to another follow the steps:
Open GCP console - https://console.cloud.google.com/home/dashboard
From here there are multiple ways that you can get to the GCP project
Click in the drop down list at the top in the header.
A dialog box should pop up with all your GCP projects in it.
Another way - Open Resource Manager - IAM -> Manage Resources https://console.cloud.google.com/cloud-resource-manager
Open folder "system-gsuite" and then "apps-script"
Once you get the GCP project displayed look for either a "Move" or "Migrate" button in the top header
I created and associated a new Apps Script project to a Google Cloud Platform project, without any issues. These are the steps I did, please try to replicate them to solve your issue:
1) Create a new project.
2) Go to "Credentials" (There's a key icon).
3) Click Create credentials->OAuth client ID.
4) In "Application type" choose "Web application".
5) Create.
6) Go Home (there's a house icon).
8) Copy "Project number".
9) In your Apps Script project go to Resources->Cloud Platform project...
10) Put the "Project Number" and click on Set Project.
11) Confirm
Docs
Google Cloud Platform Projects.

Publish an add-on from Standalone Google Apps script

I have developed a google sheet addon, I had succefully published that add-on from Google sheet bound script ie from tools->Script editor.
But If I made direct google apps script project(standalone project),I am unable to publish it,And a notification is popped up.
I research that I need it to setup it from google console,to publish standalone google app script to add-on ,But I don't found exact options to proceed.
The instruction is a very confusing for a first timer. Google keeps redirecting you to the page describing publishing editor addons, but what you really need is the page describing how to create a project on cloud platform.
https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project
Steps:
Create Project and get Project Number using instructions from link above
Go to you script. Select in the menu Resources > Cloud Platform projects... and enter your project number there
Then google will ask you to setup OAuth
After that, you can move your script to cloud platform and publish.
To publish an addon for G Suite Document editors follow the instructions here
https://developers.google.com/gsuite/add-ons/how-tos/publishing-editor-addons
The specific part about the GCP project is
Technical
The add-on script project must use a standard Cloud Platform (GCP) project. If the script project currently uses a default GCP project, you must switch to a standard GCP project. All collaborators working on the add-on should have access to the standard GCP project.

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.

Does Google Apps Script support external IDEs?

I am using Google Apps Script and was wondering if I could use any sort of editor outside of the one Google provides. (I purchased Sublime Text and would like to use that.)
The one Google provides is disgusting, with tiny text even though I have a giant screen and syntax colors that I find a bit difficult to distinguish on a white background with small text, and I don't have the beauties of Sublime like tons of custom keyboard shortcuts, all of my packages, etc.
As of today (May 2018), every scripts that you add on Google App Scripts (including scripts on Google Drive like spreadsheets) will get accessible through https://script.google.com and will have a specific id that you can get through the url by opening it.
By using clasp which handle a project (like git), you can do:
clasp clone {id}
to have your script in a local folder.
Then, after editing your file with your favorite text editor, upload it back with :
clasp push
Google has dropped support for Apps Script inside Eclipse but you can set up a local development environment inside VS Code using the Apps Script Starter kit and CLASP.
Here's a video tutorial to help you get started.
The eclipse plug-in is migrated now. You should install many
files. lastly it couldn't import my google script files.
nod-google-apps-script is depercated.
gdrive can't handle google scripts beyond exporting the project in single json file. issue issue
sublime-editor-plug-in has n't worked for me (I read the whole documents & issues)
The only working solution for me (ubuntu xenial) is clasp.
According to doc it can :
Develop Locally: clasp allows you to develop your Apps Script projects locally. That means you can check-in your code into source control, collaborate with other developers, and use your favorite tools to develop Apps Script.
Manage Deployment Versions: Create, update, and view your multiple deployments of your project.
Structure Code: clasp automatically converts your flat project on script.google.com into folders. For example:
On script.google.com:
tests/slides.gs
tests/sheets.gs
locally:
tests/
slides.js
sheets.js
N.B:. The fature of 'Manage Deployment Versions' isn't supported by eclipse plug in.
It give the following commands:
clasp login [--no-localhost]
clasp logout
clasp create [scriptTitle] [scriptParentId]
clasp clone <scriptId>
clasp pull
clasp push
clasp open
clasp deployments
clasp deploy [version] [description]
clasp redeploy <deploymentId> <version> <description>
clasp version [description]
clasp versions
By using it; you can use your favorite script editor; then push the changes.
Edit
GAS Editor Autocomplete
Thanks to #tehhowch comment.
Auto complete of google objects is almost exclusive for online GAS editor, If you use any external editor , you will only get auto complete for the functions & variables of your own script (I am not sure about eclipse).
But online editor provides autocomplete which reveals the global objects as well as methods and enums that are valid in the script's current context.
To show autocomplete suggestions, select the menu item Edit > Content assist or press Ctrl+Space. Autocomplete suggestions also appear automatically whenever you type a period after a global object, enum, or method call that returns an Apps Script class. For example:
If you click on a blank line in the script editor and activate autocomplete, you will see a list of the global objects.
If you type the full name of a global object or select one from autocomplete, then type . (a period), you will see all methods and enums for that class.
If you type a few characters and activate autocomplete, you will see all valid suggestions that begin with those characters.
You can use node-google-apps-script to edit scripts locally (described in this blog post from the google apps developer blog on 2015-12-17). This way you can use a more comfortable editor, version control and build scripts.
Caveats:
Like the eclipse plugin, node-google-apps-script requires that your add-on is a standalone script.
Debugging still requires google's script editor. With some additional setup you could run functions via the Execution API
It would be awesome if there was a Sublime Text plugin for code completion of google library methods, but I haven't found one (I don't think their default browser editor even offers this, though)
This is an answer for basic/beginner users of Intellij that are looking for code completion when writing Google App Scripts apps. Most of the answers above were helpful for getting me going, especially with Clasp. But none of them actually got Intellij to do the code complete. But this does:
Select File, Settings, Languages & Frameworks, JavaScript, Libraries.
Then on the right select Download, the scroll down to 'google-app-scripts'. (Lots of scrolling) Download and install and you're done. Almost so easy that it really shouldn't have been so hard to find.
Another option to contemplate: using "AppsScript Color" Google Chrome plugin and GAS editor shortcuts.
Here you have a list of most useful shortcuts:
https://opensourceseo.org/useful-tips-for-using-the-google-apps-script-editor/
You can just install a Google Drive command line client (e.g. https://github.com/prasmussen/gdrive) and edit .gs scripts directly.
There's also a way to edit Google Apps Scripts in Eclipse, which may be interesting. https://developers.google.com/eclipse/docs/apps_script