rudimusmaximus / BurningGAS

Demonstrate various google apps script using a menu of functions inside a fresh google sheet and container bound editor.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BurningGAS!

Random tips putting Google Apps Script to work.

Check out links for reading on our Flipboard magazine

How to use

Open a new google spreadsheet.

Pull the .gs and .html files from this repository into your sheet's attached script editor.

Enable any advanced services listed in the menu functions like sheets (both in the script editor and via link in the GCP console). See notes in the menu functions.

Refresh your sheet and use the new menu to try out various demonstrations.

Some of these will be used in our DevFlow Project

How To Get Started In Google Apps Script

This section inpired by this original gist.


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: You can write more advanced JS using Typescript and interect with standalone script projects from the cli using Node package clasp. However, if you're just starting or don't know the command line, just use the online editor and understand it's older JS if you hit an syntax error. Focus on the action plan first. Google has stated it will support modern JS in thier G.A.S. offering but will not say when. If so, there should be great performance gains too!

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.

WORKING SESSIONS

These working sessions document the creation of a set of menu driven functions in a script container bound to a sheet. Watch it evolve and read through the notes. Follow along the videos and try them yourself.

  • This section is from a phase II project inside of the repo DevFlow; to catch up on that project try reading that repo's issue 46

  • Specifically, a multi-part set of working sessions. The notes are included below along with links to the unedited recorded sessions when possible.


2018.06.20 DF Weekly Working Session - script basics part 1

Agenda with notes

  • GAS Basics working sessions to try out GAS on sheets data; some of these could be turned into demos of successful "GAS patterns"

    • Each week for a series of weeks will cover some GAS basics and share the sheet with it's script as well as the recording, so you can follow along and explore.
    • We recommend making a copy of the provided files and then working from there. If you want to make comments on the file, just add comments in the sheet we link you to.
  • Topics covered include

    • Update Multiple Values
    • Manipulate Disjoint Ranges
    • joint discovery based on interest and time
      • on open build menu calling these
      • others? practice using and presenting from editor
    • dates - cancelling working session on Aug 1st
  • This week's Cool links:

  • Unassigned Action Items: research items, problems to solve, notes, special items

    • Other DevFlows from GDEs we gave feedback (and got mentioned) in a google developer expert's DevFlow for an org team. This G+ post shows him listing a document for feedback and the document itself has comments you can review in comment mode. He has a great idea about including manifest files (more later). IF you are ever keen and the post is still up, check it out for a look at open collaboration about methods.
    • ideas for GAS series working sessions
      • use the "Gist query my sheet" demo to build a 2d array from sheet data
        • try out a few patterns on this data
      • grab real problems posed in G+ for discussion; for example this one has a recommended solution where the answer involves a simple and an installable trigger. Triggers might be a topic
        • setup a series to solve, then work the list practicing working ing GAS
      • Incorporate manifests
  • Next Week: part 2

2018.06.27 DF Weekly Working Session - script basics part 2

Agenda with notes

2018.07.04 WS-GAS Basics Part 3

Canceled due to holiday; merging with General Session II.

2018.07.11 GS-General Session II (and WS-GAS Basics Part 3)

Agenda with notes

Ready to move on to add-ons?

Try this repo where you can see some of these functions translated into sheets add-ons. DevFlow is also about workflow for professionalizing developmenet of google apps script. Here are a few links: Install and try our add-on from an unlisted link: rudimusmaximus/DevFlow#65

If you want to see more about the history of the making of the repo with lots of readme links, see rudimusmaximus/DevFlow#46

Remember to star the repo, thanks.

We will be cleaning up the documents, so look for updates over the comming months.

About

Demonstrate various google apps script using a menu of functions inside a fresh google sheet and container bound editor.


Languages

Language:JavaScript 100.0%