Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rudimusmaximus/bfe0ac7ca872bb0b2f8a7cb30a524eff to your computer and use it in GitHub Desktop.
Save rudimusmaximus/bfe0ac7ca872bb0b2f8a7cb30a524eff to your computer and use it in GitHub Desktop.
Getting started in google apps script

How To Get Started In Google Apps Script

Initially intended to extend G Suite apps, I like to think of Google Apps Script as a gateway to more kinds of development. Think of it as workflow glue and the power of programming that can interract with Google Apps and external APIs too!

Purpose

Provide a living document for whenever someone asks, " so, how do i get started with Google Apps Script?".

Working Outline

Just the orgainizing principles and some key links.

1 Starting point: Good Things to Keep in Mind

Scripts are 'bound' to a container like sheets, docs, slides or forms. These can be accessed from the containing doc and opened say in sheets by going to the menu Tools > Script editor. Scripts can also be standalone for addons or web apps. Your script home page is a dashboard found here script.google.com. The help link there will get you to an explanation of the dashboard.

javascript basics

See this codeacademy link.

working with 2d arrays

Getting data into and out of a sheet using 2d arrays and few methods is the key to moving on from custom functions to macros to executing business logic on an array and then writing the results back to your sheet.

2 Remember, "It's basically Javascript" BUT an important note on standards

The documentation alludes to app script's basic javascript feature support which is 1.6 and some of Javascript 1.7 and 1.8.

GAS support for javascript features can be confusing to a newcomer, especially when learning about javascript from the ECMAScript standards.

The ECMAScript (ES) implementation called "V8" is the javascript engine used by apps like chrome, node.js, opera, etc. This engine supports some of the latest ES javascript conventions.

However, google apps script is running on the servers and we have yet to see when or if the Google App Script (GAS) team will support more recent ES so developers can write consistently when writing javascript whether it's a web app or inside a GAS.

Star and follow this issue: https://issuetracker.google.com/36764074
Advanced users: there are some emerging transpilers modified for GAS but I haven't worked with them yet. Babel?

3 Key Google links

Welcome page about scripts

Start with this Overview of Google Apps Script. It includes a link to codeacademy for learning javascript if you need help there.

4 People and their books, classes, helpful websites or other activities they want to share in this context

Please add to the comments and I'll include here over time. Thanks so much.

From conferences on youtube

Please see the nice add-ons introduction and the end comments; in the middle is also a demo of ultradox which i haven't used. Building G Suite add-ons with Google Apps Script (Google Cloud Next '17)

From the comments below this post (thanks! VERY MUCH :) )

From interesting posts on the Web

This great gist by Amit Agarwal

For tutorials covering the basics, check out The website of Barrie Roberts

This G+ post has lots of real uses for GAS. Highlights

5 Action plan

A few options for how you could go about learning more and what that path might look like. Try using the above links to find out how to do the following:
1 Write a custom function in a container bound sheet script
2 Call that function from the sheet
3 Play with recording macros and editing the scripts they generate (in macros.gs)
4 Lookup the documentation on some of the methods you see in the scripts; For example, go to the api documentation and search for more information on the methods you see used in the macros.
Such as this macro recording me selecting a range and then simply entering the text what into E5:

/** @OnlyCurrentDoc */

function testmacro() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('E5:F12').activate();
  spreadsheet.getCurrentCell().setValue('what');
  };

In the above, you could search the api documentation for 'SpreadsheetApp.getActive()' and learn that it "Returns the currently active spreadsheet, or null if there is none." This is an object assigned to the spreadsheet variable in your macro example above. Simarlarly you could search for 'getRange' or 'getCurrentCell()' or inside each of those 'activate()' or 'setValue' respectively. Make the connection between the api documentation and how you see the macros recording your actions. HINT: inside the script editor you can hit Ctrl + Spacebar and see a list of the services available to the script. Including the 'SpreadsheetApp' you are exploring. You can scroll or type to find the service you want and on each find hit enter followed by a period to walk the list of classes or methods for the current selection. This is effectively 'walking the API' which I find more interesting way to figure out what's available than trying to read the API documentation. Put the two together and you really start to get it.

SpreadsheetApp.getActive().getRange(a1Notation).getValues();

If you look at the hints while walking the api as in the example above you can notice getRange wants a1Notation (there are others) and that .getValues returnes a [[]] 2d array - an object of rows whose rows are arrays...a spreadsheet range :)

HINT: now just try getting and setting one value vs many and you are on your way to working with scripts. As you advance, checkoout libraries to see what proplems are common enough to require libraries. Star the gists to browse and file the links.

Learn more by solving one problem at a time. Join the DevFlow Project to learn how to create a sheets addon and test your understanding. Good luck. Help each other.

To Do

TODO: more as possible, please add comments especially if i misstate anything. Thanks.

  • add some get and set examples for data 2d array basics...add links to patterns series for more advanced work.

THIS MOVED into repo BurningGAS

@rudimusmaximus
Copy link
Author

rudimusmaximus commented Jul 28, 2017

Let's evolve this overtime. Looking for comments or suggestions. Just add them below and i'll incorporate what makes sense. See the outline above. The intent is not to write a book but a single markdown file with links to get started.

@Blueprinter
Copy link

Link to Google Site - Apps Script - Getting Started
Apps Script - Getting Started

@oshliaer
Copy link

@rudimusmaximus
Copy link
Author

Nice add-ons introduction and end comments, also a demo of ultradox which i haven't used.
Building G Suite add-ons with Google Apps Script (Google Cloud Next '17)

@rudimusmaximus
Copy link
Author

All notes so far, incorporated into the GIST. Please add more if you like!

@rudimusmaximus
Copy link
Author

TODO: add some get and set examples for data 2d array basics...add links to patterns series for more advanced work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment