Bruce Mcpherson has been busy again and this latest post introduces ‘SuperFetch’ the new Google Apps Script library which works as a proxy for
. SuperFetch has some useful additional functionality including: built in caching and compression, standard response format and error handling, and built-in JSON parsing.
SuperFetch also has some useful features often required when using third party APIs including delaying between requests and rate limiting. Bruce has promised some additional posts detailing more complex API configuration options including authentication.
Unit testing your code with this Apps Script Unit test library as you go along will makes it easy to immediately catch errors, and keeping a running test repertoire ensures that you don’t break anything.
When you start developing more complex Google Workspace solutions like add-ons and Chat apps it’s worth considering how you will test, debug and refactor your code. As noted in this post from Bruce Mcpherson the Apps Script community has published a number of different solutions/approaches to unit tests, a number of these appearing in Pulse. This latest post from Bruce looks at the bmUnitTest library he has developed highlighting how it can be set up and used.
JSONata is a lightweight query and transformation language for JSON data. Inspired by the ‘location path’ semantics of XPath 3.1, it allows sophisticated queries to be expressed in a compact and intuitive notation. A rich complement of built in operators and functions is provided for manipulating and combining extracted data, and the results of queries can be formatted into any JSON output structure using familiar JSON object and array syntax. Coupled with the facility to create user defined functions, advanced expressions can be built to tackle any JSON query and transformation task. – JSONata
JSONata is a solution better understood by trying it out, which you can do thanks to the script project shared by Max on Twitter or on the JSONata website. If you are interested in data query/manipulation solutions for Google Apps Script you might also want to check out our previous post on using AlaSQL for Apps Script.
A simple and small Google Apps Script library for quickly and easily finding and updating records in Google Sheets with a familiar ORM-like syntax
Following our previous post on Converting Google Sheets cell values to an object array, Vance Lucas (@vlucas) got in touch to highlight the SheetQuery library he has created which as well as being able to get Google Sheet data as an object array has some additional nice features for updating cell values. As Vance highlights:
sometimes working with spreadsheets to find and update specific rows of data can be awkward and tedious. There is no direct built-in way to search for specific values in rows by headings. To do this with the Google-supplied APIs, you have to keep track of row index numbers, column index numbers, and arrays of row data while planning your updates. It’s not fun code to write, and it’s relatively error-prone, especially if you are deleting rows, which causes the row index numbers to shift dynamically.
The library includes a
method which can be used to apply a filtering function to select the rows of a spreadsheet to be read and/or updated. If you are regularly developing scripts that interact with Google Sheets data this can be a great library to keep in mind.
I recently came across GAS — Google App Script and immediately the first hurdle I had to overcome to was make my NPM packages available on there. I had to hop through a couple loops to make this happen. I wanted to call out the steps in this blog so it’ll hopefully help someone out there as well.
In Pulse we’ve previously highlighted a couple of approaches for using NPM libraries in Google Apps Script. The linked source post come from, recent guest on Totally Unscripted, Nima Poulad, Senior Software Engineer at DocuSign. Nima highlights a quick and dirty approach of using
on hosted NPM libraries, but goes on to show how Browseify can be used to convert NPM libraries, highlighting some considerations for this approach.
While working on Sheets Workbook functions – converted to Apps Script I realized that I’d need to tackle the query language at some point, so I figured I may as well go the whole hog and implement a comprehensive SQL variant for Apps Script. Luckily though, I found alasql so with a few tweaks it was ready to go!
A couple Google Apps Script community contributors have shared solutions for using the AlaSQL.js library. Latest come from Bruce Mcpherson, which is included as the source link. If you use Bruce’s fiddler library his post is worth checking out as he provides examples showing how both libraries can be used together. Another version of AlaSQL.js you should look at is Alex Ivanov’s AlaSQLGS which also includes some data and code samples.
More technically, this library can be used to send http requests via
, interacting with api endpoints in raw form. By bringing it down to a lowest layer on this platform, you get the following benefits:
All of the options, features, and abilities that are available. No compromises.
Ability to batch the requests in bulk. Performance can be significantly improved and run times lowered.
If you’re looking for a way to duck under the
minute limit to your scripts, the last bullet point should be particularly interesting.
Sometimes you need to generate some fake data for a spreadsheet. In this post I’ll cover a few utilities in 2 separate libraries that can help with this.
Bruce Mcpherson has put together a Google Apps Script library which is a port of Faker.js and elements of d3.js to make it easier to generate random data in your projects. You can see the full list of Faker.js methods which includes a wide range from names/addresses to dates to just lorem text. The library can also generate various fake datasets, strings and selectors.