AppsScriptPulse

Validate postal address with the new Google Maps Address Validation API and Google Apps Script

 

Validate addresses using Google Maps Address Validation and Apps Script. Discover onleeaddress the add-on for Google Workspace.

I missed the announcement in November 2022 that there is a new Google Maps Address Validation API. I also missed this post from Stéphane Giron showing how you can use the Address Validation API in Google Apps Script.

The concept is simple, you provide the Address Validation API with what you think is a correct address and the API returns information on each component of the address and additional metadata. Visit the source post for more details on setup and some example code.

Source: Validate postal address with the new Google Maps Address Validation API and Apps Script

Find all matching values in Google Sheets cells with Google Apps Script

Learn how to search and find all values in an entire Google Sheet spreadsheet, in a specific sheet tab or in a range with Apps Script.

Handy little snippet from Scott Donald on using the Google Apps Script TextFinder class to find all the occurrences of matching text in a Google Sheet. The bit I particularly liked in this solution was how Scott used a .map method to return an object array of cell hits including A1 notation:

Array containing an object for each sheet containing the sheet name and the cell location (Image credit: Scott Donald)

Follow the source link for more information including a video tutorial.

Source: Find All Values in Google Sheets with Apps Script – Yagisanatode

Hiding/deleting non-consecutive rows and columns in Google Sheets using Google Apps Script

These are the sample scripts for hiding and deleting rows and columns on Google Spreadsheet [sic] using Google Apps Script. I sometimes see the questions for hiding and deleting rows and columns on Spreadsheet at Stackoverflow. So here, I would like to introduce the sample scripts for this.

In SpreadsheetApp there is the .deleteRow() and .deleteRows(), but when you have a lot of data or non-consecutive rows it can really eat into your Apps Script runtime limit. In searching for a better way of doing this I found this great solution from Kanshi Tanaike on Stack Overflow which uses the Google Sheets Advanced Service to delete multiple rows using one API call!

Using Sheets.Spreadsheets.batchUpdate isn’t just limited to deleting rows and for more examples see the source post which includes examples for hiding and deleting both rows and columns.

Source: Hiding and Deleting Rows and Columns on Google Spreadsheet using Google Apps Script

Google Apps Script trends in Stack Overflow for 2022

From the above results, it can say that the current Google Apps Script has still been useful for a lot of users. But, the number of questions for one answerer is increased proportionally to the square of the year. Furthermore, the ratio of the solved questions for the total questions in 2022 is lower than that of 2021. So, in order to improve these issues, it is considered that growing answerers will be one of the important factors for the selectivity of Google Apps Script by users.

Kanshi Tanaike has recently published the 5th annual review of Google Apps Script tagged questions and answers on Stack Overflow [google-apps-script] to include data from 2022. This type of data always has to be read with caution. For example, whilst the total number of questions has again declined this year it could be argued this is because there is now a much bigger published knowledge base of both official and community resources. Declines in the number of people answering questions is more concerning. If you are someone who contributes to Stack Overflow a big thank you!

Source: Trend of google-apps-script Tag on Stackoverflow 2023

Merging multiple PDF files as a single PDF and converting all the pages in a PDF to PNG images using Google Apps Script

This is a sample script for merging multiple PDF files as a single PDF file using Google Apps Script. [and] This is a sample script for converting all pages in a PDF file to PNG images using Google Apps Script.

Kanshi Tanaike has recently been exploring and sharing some Apps Script solutions for handling PDF Documents using the PDF-LIB JavaScript library. So far they have looked at merging PDF files as well as converting PDF pages into PNG images.

The solution uses fetch and eval to load PDF-LIB, but with a minor modification hoisting the declaration of setTimeout you can also copy the source code into the script editor and avoid the evils of evals (a modified example here).

The Apps Script execution runtime limit will be a factor in the size of PDF Documents you can handle, but for smaller jobs a great solution to keep in mind.

Source: Merging Multiple PDF Files as a Single PDF File using Google Apps Script and Converting All Pages in PDF File to PNG Images using Google Apps Script

Apps Script has deprecated the Contacts service. Instead, use the People API advanced service | Release Notes | December 16, 2022

Apps Script has deprecated the Contacts service. Instead, use the People API advanced service. Refer to Migrate from Contacts service to People API advanced service.

Having taken bit of a break from Pulse over the festive period I had missed the December release note announcing the deprecation of the Contacts service, ContactsApp. There isn’t much time to update your code as the service will no longer function after April 30, 2023. Google have however provided detailed guidance on migrating from Contacts service to People API advanced service.

[HT to Pablo Felip @pfelipm for flagging this update on Twitter]

Source: Release Notes  |  Apps Script  |  Google Developers

Quick backup solution for Google Apps Script by creating versions in Google Docs

Get security and peace of mind by backing up your Google Apps Script files to Google Docs and trigger for continuous backup.

We’ve featured a couple of methods for restoring Google Apps Script code in Pulse, but most of these rely on recovering a deployed version of the script. Stéphane Giron wields his Apps Script hammer and skilfully demonstrates how you can use Google Docs and it’s built-in version history as a way of keeping a backup copy of your code.

Source: Quick and not so Dirty backup solution for Google Apps Script Code

Fix Google Apps Script file order problems with Exports 

How to fix Apps Script file loading order and defintion visibility problems with an Exports object.

It’s good practice to keep class and namespace definitions in separate files and avoid defining functions or variables in the global space. However, App Script doesn’t give you control over the order in which it loads files. If you reference a class or a namespace from one script file, it may not yet be defined. This is where an Exports object comes in.

As your script projects get larger and you start splitting out across script files you may find you need a little more structure. Class and namespace definitions are a good way to structure your code. Even when you do this you can still encounter problems with parts of your script trying to run before they are fully loaded.

This was a particular issue when the V8 runtime launched in 2020. This was fixed in June 2022, but it can still be an issue depending on how declarations are made in your code. To find out more about why this happens and how to fix it this post by Bruce Mcpherson shows how an Exports object can be used to structure your code.

Source: Fix Apps Script file order problems with Exports – Desktop Liberation

Using JWT as a license key in Google Apps Script Google Workspace Add-ons

Image credit: Zzapps

Many developers want to offer specific, additional functionality for specific users. One very common scenario is to differenciate in users that pay for this functionality.

When you deliver an add-on, you want to know whether this user has this special access. We know this as a license.

In this blog, I will show you how we can let the add-on know what the user’s license is. We are going to do this by giving the user a key, where they can ‘unlock’ functionality by pasting this in their add-on.

Here’s an elegant solution from Riël Notermans (Zzapps) for letting users unlock premium functionality in your Workspace Add-on without relying on an external fetch or database by using an encrypted JWT web token.

You can include various data in the token and this example a subscription email and expiry is included which can be checked locally, for example, comparing the email from Session.getActiveUser().getEmail().

Source: Use JWT as a license key in Google Apps Script add-ons

How to use Flutter with Google Sheets, Apps Script, and Codemagic | Codemagic Blog

In this article Jahswill Essien describes how to use Google Sheets with Flutter via Google Apps Script.

This article assumes the following:

  • You have experience using the basics of Flutter and can call APIs and read an existing codebase
  • You have little to no understanding of Google Apps Script
  • You have some experience using Google Sheets or spreadsheets in general

I’m sure many of you reading this post will already be familiar with Google Apps Script and have little/no experience deploying Flutter apps but I also know a lot of Google Apps Script developers are keen to try new stuff.

If deploying mobile apps is a thing that interests you I’d highly recommend also looking at Google no/low code development platform, AppSheet, which enables you to quickly create/deploy apps often using Google Sheets as a backend. If, however, you need custom graphics or pixel perfect UI, solutions like Flutter would be my personal starting point. Enjoy!

Source: How to use Flutter with Google Sheets, Apps Script, and Codemagic | Codemagic Blog