AppsScriptPulse

SheetQuery: An ORM-Like Query Builder for Google Sheets and Google Apps Script

Image credit: Vance Lucas

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 .where 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.

Source: SheetQuery: An ORM-Like Query Builder for Google Sheets and Google Apps Script

Converting Google Sheets cell values to an object array with heading keys using Google Apps Script

This is a sample script for converting the values of Google Spreadsheet to an object using Google Apps Script.

I have a minor obsession with methods for converting Google Sheets data to an object array. Over the years I’ve documented various approaches I’ve developed on my personal site, like this one, but this solution from Kanshi Tanaike has to be my new favourite:

function myFunction() {
  const sheetName = "Sheet1";
  const [headers, ...rows] = SpreadsheetApp.getActiveSpreadsheet()
    .getSheetByName(sheetName)
    .getDataRange()
    .getValues();
  const res = rows.map((r) =>
    headers.reduce((o, h, j) => Object.assign(o, { [h]: r[j] }), {})
  );
  console.log(res);
}

Source: Converting Values of Google Spreadsheet to Object using Google Apps Script

Opportunities and workflows inlining Google Apps Script libraries – Desktop Liberation

This article will look at some of the opportunities you’ll have when you pull in your libraries inline rather than leaving them as references to external files, all without leaving the IDE

For the more advanced Google Apps Script developer this is a great article to get your teeth into which should also hopefully give you some tips to help manage and maintain complex Apps Script projects.

Source: Opportunities and workflows inlining Apps Script libraries – Desktop Liberation

Building a Google Calendar add-on and publishing it in the marketplace

Image credit: Gareth Cronin

I’ve long been interested in using one of the big office productivity platforms to build an embedded add-on. For a solo developer it’s a no-brainer: the platform takes care of the requirements above, and when the platform has a marketplace, there’s even a ready to go distribution channel to take it to market! The only real reason I’ve resisted it so far is fear of the slog of platform approval processes and required collateral. In this story I’ll explain how I felt the fear and did it anyway 😀

Google OAuth verification and Workspace Add-on app review can be quite daunting the first time you go through the process. In this post from Gareth Cronin he shares his own personal journey getting his JIT Time Google Calendar Add-on verified and approved. There are some great tips and resources shared in the post including how to show the  OAuth client ID in the add-on demo video submitted as part of the verification processes.

Source: Building a Google Calendar add-on and publishing it in the marketplace

List all users of a Google Workspace domain, remove inactive users and force reset users’ passwords – Digital Inspiration

Amit Agarwal has recently been busy continuing to publish lots of incredibly useful Google Apps Script tips and snippets on his ‘Digital Inspiration’ blog. Three recent posts might be of particular interest to Google Workspace administrators:

[This Google Apps] Scripts gets the name and email address of users in the organization and saves the list inside a Google Spreadsheet. This script can only be executed by the domain administrator.

Source: List All Users of a Google Workspace Domain in Google Sheets – Digital Inspiration

Learn how the Google Workspace admin can change the Google account passwords of multiple users in their organization automatically with Google Apps Script.

Source: How to Force Reset Google Workspace Users’ Passwords with Apps Script – Digital Inspiration

Learn how to find inactive users in your Google Workspace domain and delete the dormant accounts to save on your monthly bills.

Source: Find and Remove Inactive Users in your Google Workspace Domain – Digital Inspiration

How to build an automated PDF report in Google Sheets using Apps Script 

Grab this automated ConvertKit Report in Google Sheets to monitor your email list growth and use it to project your future list growth.

Ben Collins shares the solution he uses to produce a daily ‘ConvertKit’ PDF report. Even if you don’t use ConvertKit this post is still worth a read as the basic model of getting data from a third party API into Google Sheets and sending a PDF summary could come in handy. Perhaps not surprising given this post comes from Ben it includes some clever Google Sheet functions to prepare and shape data.

Source: Automated ConvertKit Report In Google Sheets

Pull libraries inline to your Google Apps Script project – Desktop Liberation

Inline converter

This piece of work was both challenging and a lot of fun to produce, and it’s something I’ve wanted to get round to for a long time.  Apps Script libraries are a great way to reuse work you and others have done, but you have to be careful that they don’t get out of date. Libraries that refer to other libraries are complex to keep up to date, and worst of all they may disappear or their permissions change at any time.

Google recommend you don’t use them in Add-ons, and although they focus on ‘load efficiency’ (I did a study on this a few years back and found absolutely no evidence of a  measurable load penalty for libraries: see  Measuring library load speed), the above are probably better reasons to bundle all the code you use in your app or Add-on.

This builds on the work from Import, export and mix container bound and standalone Apps Script projects and I release it as a library (which you can of course use to inline it to your own project if you want!)

As noted by Bruce there may be a number of reasons you might want to inline libraries as part of your Apps Script projects, particularly if you are reusing third-party libraries where there is a risk the code could disappear.

Source: Pull libraries inline to your Apps Script project – Desktop Liberation

Google Apps Script: How to export Google Sheets as PDF – YouTube 

In this video you will see how you can use Google Apps Script to export a Google Sheets document as a PDF

It’s been a while since we featured a video tutorial from Chanel Greco, but that doesn’t mean she hasn’t been busy. In this recent tutorial from Chanel you can learn how to use Google Apps Script to export a Google Sheet as a PDF Document. You can watch this and other videos from Chanel on the saperis YouTube channel.

Source: Google Apps Script: How to export Google Sheets as PDF

Apps Script Basics – Using Form Responses – Learning Google Workspace & Apps Script

In this post, we’re going to look at how we can work with the responses a form user submits.

We’ll look at two main ways, 1) Getting the form responses from a Google Sheet, 2) Getting the form responses directly from a Google Form.

To show some practical uses of this, we’ll do the following:

  1. Set up a simple problem-reporting log, which will email the relevant parties the problem in a classroom. We’ll do this via the Sheet and via the Form.
  2. Get students’ pieces of writing submitted via a Google Form and copy them to their individual sheets, ready to have feedback added.
  3. Set up a simple appointment system, which will update itself as people take the appointments, leaving only the available ones on the Form.

This post taken from Barrie Roberts’ latest book “Beginner’s Guide to Google Apps Script 2 – Forms“, available on Amazon here. The post covers some different ways that you can interact with Google Form responses and contains lots of useful code and tips that might be useful to other Google Apps Script developers.

Source: Apps Script Basics – Using Form Responses – Learning Google Workspace & Apps Script

[Google Sheets] Word Highlighter (made using Google Apps Script)

I have created a handy highlighting tool using Google Sheets and Google Apps Script. The specification of this tool is very simple.

  1. The user pastes a message into the certain cell (A2).
  2. The tool checks if the message contains some words which listed in another dedicated sheet(Spam Word List).
  3. The tool highlights (bold and color red) the found words in the message.

Here is a nice post demonstrating how you can use Google Apps Script to highlight keywords within a Google Sheets cell. The solution uses  SpreadsheetApp.newTextStyle() to create a custom style which is then applied to part of the cell text.

Source: [Google Sheets] Word Highlighter