Tuesday, 17 December 2024

Exponential Backoff

The following Google Apps Script is designed to explore Exponential Backoff - a process by which when something fails you try again a set number of times whilst increasing the delay between each attempt, up to a certain point.

I needed this for a tool I built which adds Guests to a Calendar event from a Google Form submission. Whilst I was using ScriptLock to prevent simultaneous submissions, the code ran so fast that it would infrequently trip the Calendar API with the following error message "API call to calendar.events.patch failed with error: Rate Limit Exceeded".

By infrequently I mean a reported issue only once in 3,500 submissions over the course of 12 months. Enough however to take the opportunity to learn about Exponential Backoff and to squash that single instance.

Just a note that this is one way to implement it.

Sample Apps Script code for Exponential Backoff
Sample Apps Script code for Exponential Backoff

Tuesday, 19 November 2024

Copy or move file into folder Tool

The following Google Apps Script tool allows you to quickly copy or move existing files into existing folders within Google/Shared drive. This is quite a niche tool so it is anticipated you would already have a Google Sheet of file IDs/URLs, though there is the option to select an existing Drive folder of files and automatically bring them into this tool.

You can continue to append further rows to the Google Sheet as existing ones will be skipped once the ‘Status’ column has automatically been marked as ‘Completed’. Alternatively you can clear the Sheet each time for a fresh start.

Quickly copy or move existing files into folders via a Google Sheet
Quickly copy or move existing files into folders via a Google Sheet


Tuesday, 22 October 2024

Append Drive folder permissions Tool

The following Google Apps Script tool allows you to quickly append new permissions to existing folders within Google/Shared drive. This is quite a niche tool so it is anticipated you would already have a Google Sheet of folder IDs/URLs, though there is the option to select an existing Drive folder of folders and automatically bring them into this tool.

This tool is a modified version of the Append Drive files permissions tool.

By inserting email addresses using a comma-and-space format you can optionally select to send a notification email to the new user(s).

You can continue to append further rows to the Google Sheet as existing ones will be skipped once the ‘Status’ column has automatically been marked as ‘Completed’. Alternatively you can clear the Sheet each time for a fresh start.

Quickly append new file permissions via a Google Sheet
Quickly append new folder permissions via a Google Sheet


Tuesday, 24 September 2024

Append Drive file permissions Tool

The following Google Apps Script tool allows you to quickly append new permissions to existing files within Google/Shared drive. This is quite a niche tool so it is anticipated you would already have a Google Sheet of file IDs/URLs, though there is the option to select an existing Drive folder of files and automatically bring them into this tool.

By inserting email addresses using a comma-and-space format you can optionally select to send a notification email to the new user(s).

You can continue to append further rows to the Google Sheet as existing ones will be skipped once the ‘Status’ column has automatically been marked as ‘Completed’. Alternatively you can clear the Sheet each time for a fresh start.

Quickly append new file permissions via a Google Sheet
Quickly append new file permissions via a Google Sheet

Tuesday, 27 August 2024

Check comma separated email address is valid

The following Google Apps Script is designed to loop through a Google Sheet cell of email addresses that have been separated by a comma and space. It then uses a regular expression (regex) to confirm the email address meets the correct formatting criteria.

This code was developed as a way of implementing additional checks when asking users to be precise in how exactly they enter multiple email addresses. So if they were to forget the space for instance it could alert them, before the rest of the code risked failing as whatever task it was designed to do.

Regular expression to check the format of an email address
Regular expression to check the format of an email address

Tuesday, 30 July 2024

Change Drive ownership without email notification

The following Google Apps Script is designed to change ownership of a Google Drive item without sending the default email notification to the new owner. Please note this will only work within your organisation (i.e. on the same domain) and not between personal Google account (where consent is required by Google).

Snippet of code for changing Drive ownership
Snippet of code for changing Drive ownership


Tuesday, 2 July 2024

Tuesday, 4 June 2024

Correct date formats in a Google Sheet

The following Google Apps Script is just one way you could search through data within a Google Sheet, pinpoint all date-values (no matter where they are), check their format (e.g. dd/mm/yyyy) and update it to a format of your choosing if necessary.

This function has been useful when American/British date formats have managed to make their way into a Google Sheet.

Screenshot showing difference between American/British date formats
Screenshot showing difference between American/British date formats