AppsScriptPulse

Programmatically manage and apply Drive Labels using new API functionality

Many of our customers already take advantage of the Drive Labels capabilities to classify content and implement policies on their Drive files for governance and Data Loss Prevention.

Today, we’re happy to announce a highly requested update that will enable you to programmatically manage labels at scale via Drive APIs.

Google Workspace devs might be interested in this update to the Drive Labels API which enables additional functionality. As noted in the source post:

The new Drive Labels API supports reading Drive Label taxonomies. New functionality in the Drive API can be used to apply labels, set fields on files, and find files by label metadata. As a whole, these new API features enable numerous use cases including, bulk-classification, Apps Script driven workflows, third-party integrations, and other organizing and finding needs.

The post includes links to a number of useful resources including reference documentation.

Source: Programmatically manage and apply Drive Labels using new API functionality

Benchmark: Process cost for Parsing XML data using Google Apps Script

Note: Process time has been graphed on a log scale

In order to retrieve the values from XML data, when XML data is parsed using Google Apps Script, there are several methods for parsing the data. … For example, Class XmlService cannot only parse and read XML data but also update XML data and create new XML data. In the current stage, the process cost of Class XmlService is much higher than those of “cheerio” and the simple script using regex.

In Pulse we’ve previously highlighted the cheerio JavaScript library for parsing/extracting content from XML data. The cheerio library can easily be added to Google Apps Script projects as a library (see the GitHub repo for installation). Google Apps Script also has the XML Service, which can also be used to work with XML data. In this latest benchmark report from Kanshi Tanaike they look at the process cost for reading XML data using XML Service, cheerio and using RegEx. The results highlight a higher process cost for using XML Service particularly if you are handling reading 1,000 or more XML elements. The source post contains further details of the test and a summary of the results.

Source: Benchmark: Process cost for Parsing XML data using Google Apps Script

Dependent dropdown lists for Google Sheets (and lots of other Google Apps Script goodies)

Updated the script for dependent lists, and now it supports new options. New for 2022:

Dependent drop-down lists can be used to create a dynamic list of choices in Google Sheets. When the user makes a selection from the first drop-down list, the choices in the second drop-down list will be updated based on the selection. This can be used to create a cascading list of choices.

If you are looking for a nice solution to build dependent drop-down lists in Google Sheets this is a great solution from Max Makhrov. For more experienced Google Apps Script developers the solution incorporates some clever snippets both from Max and a number of other members of the community. Some highlights include: converting a column index into corresponding column letter; a tasker to batch apply updates to a Google Sheet; ChuckyCache for objects above 100Kb; and a reference to a zip compression solution. All these are referenced in the source code provided in the post.

Source: Dependent Drop-Down Lists For Google Sheets v2022

Quickly format multiple Google Sheets with Apps Script

In this post, we’re going to see how we can very quickly format multiple Google Sheets with a little help from Apps Script.

The idea of this post, came from the Department of Education in Hawaii, where they have over 300 schools and a guy who works there told me he had to format over 300 Google Sheets the same way, and wondered how this could be done with Apps Script.

Easy I said! And I thought it was a typical example of how a little knowledge of Apps Script can help you speed up your work and allow you to spend less time doing boring, repetitive work, and focus more on the data itself.

Let’s see how it’s done!

This is a nice real world example of how Google Apps Script can be used to make a manual routine task more efficient. The post by Baz Roberts includes a detailed explanation of what is going on in the code making it also a great learning resource. If you have some more complicated Google Sheets formatting in mind you might want to also look at Google Sheets Macros, which lets you record every action you take within the spreadsheet creating a script you could call similar to the format functions included in the post.

Source: Quickly format multiple Google Sheets with Apps Script (also available on bazroberts.com)

GWAOw! 3 – Crop Sheet by Eric Koleda (how to keep Google Workspace Add-on development simple with custom menus)

Crop Google Sheet Data to the data range or a selection in 2 button click with Crop Sheet. Full Walkthrough

Does this Google Workspace Add-on developer story sound familiar? You are able quickly write the code that executes your add-on functionality, but then you spend days buried in HTML or Card Service making the UI. The Crop Sheet add-on by Eric Koleda highlighted in this latest GWAOw! episode is a great example of what is possible just by using custom menus. For what it is worth the source code (all 73 lines including comments!!!) is on GitHub. Follow the source link for the video demo from Scott Donald and links including the GitHub repo.

Source: GWAOw! 3 – Crop Sheet by Eric Koleda – Yagisanatode

Automatically backup Google Drive folders to Cloud Storage with Google Apps Script

Image credit: Stéphane Giron

Few days ago, with the launch of French region ‘europe-west9’ in GCP, I made an apps script to backup a Drive folder to Cloud Storage. It is a cool script and works nicely but after some exchange, we can make it better.

So here I come back with onleebackup an open source code to backup multiple Google Drive folders to cloud storage with synchronisation.

A very interesting open source project from Stéphane Giron which lets you backup Google Drive folders to Google Cloud Storage. An important caveat is with Google Apps Script limitations like script runtime and URL Fetch POST size this won’t work if you have gigabytes of data. The code has some nice features like handling Google Docs/Sheets/Slides file types, converting them to equivalent MS Office formats as well as management of Google Drive shortcuts, which requires calls to v3 of the Google Drive API. The source post provides details for setting up onleebackup, which also includes a link to a previous post with code highlights.

Source: Automatically backup Google Drive folders to Cloud Storage

Benchmark: Process cost for HTML Template using Google Apps Script

Image credit: Kanshi Tanaike

When we use HTML in the Google Apps Script project, in order to show the values from the Google Apps Script side, the HTML template is used. When I used the HTML template with a large value, I understood that the process cost can be reduced by devising a script. In this report, I would like to introduce the process cost of the HTML template using the benchmark.

A great feature of Google Apps Script is the ability to create and serve custom HTML, often used to interface data you have in Google Workspace such as Google Sheets. Google highlight a coupe of different ways you can mix Apps Script code and HTML. Some of these ways are better in terms of process time and this report from Kanshi Tanaike highlights the cost of calling Apps Script functions as scriptlets in HTML templates. The good news is you can avoid delays in your web app rendering by making asynchronous calls with google.script.run, which you can read more about in Google’s best practices documentation.

Update: I’ve replicated this benchmark (smaller dataset) with google.script.run and it was only marginally slower (0.3s) than the ‘create HTML table with Google Apps Script’:

Source: Benchmark: Process cost for HTML Template using Google Apps Script

Combining Google Apps Script with Google AppSheet

Combining Google Apps Script and AppSheet

In this blog I am going to show you how to combine Google Apps Script with Google AppSheet to make automation even more powerful.

Whilst Google AppSheet is marketed as a ‘no-code’ development platform for coders there have been a number of ways to add some customisations to AppSheet apps. Previously webhooks were the main way you could do this, but the recent Apps Script connector for AppSheet makes it possible to call and if required pass parameters from AppSheet into custom Apps Script functions.

If this is something you would like to learn more about Aryan Irani has continued his AppSheet tutorial series on Medium with this post which goes through the step-by-step process for setting up and using Apps Script code in AppSheet. Click through the source link to find out more.

Source: Combining Google Apps Script with Google AppSheet

Working with the Google Drive API Revisions history: Tips for handling revision merges with Google Apps Script

Having spent quite a bit of time working with the Google Drive API Revisions resource in this post I thought it would be useful to share some of the lessons and solutions I’ve picked up along the way. For this I’ll be sharing code snippets for interacting with the Revisions resource with Google Apps Script, but the solutions discussed could easily be applied to your programming language of choice.

Source: Working with the Google Drive API Revisions history: Tips for handling revision merges

How to access an API with Google Apps Script and API calls and Google Sheets manipulation

In this video you will learn how to access an API with Google Apps Script.

Chanel Greco has created this video tutorial which walks through some different ways you can interact with other sites with Google Apps Script to get data into Google Sheets. For the tutorial Chanel uses the Weather API and by coincidence Luxman Ravindrakumar has also shared a similar tutorial on Medium explaining how to use the OpenWeather API. So if you prefer learning by watching or reading you’ve no excuses :). Check the sources links below for both tutorials.

Sources: How to access an API with Google Apps Script (YouTube) and API Calls & Spreadsheet Manipulation With Google Apps Script