Tuesday, 17 January 2023

Organise files into a JavaScript Object

The following Google Apps Script is designed to go through a folder of Google Drive files where a number of tutors have individual files for groups of students they teach. The code will collate all of the relevant files (specifically their IDs) that belong to each tutor, so that at a later date we can loop through the organised data set and create individual Google Sheets for each tutor and compile their student data into it.

What this code ultimately allows us to achieve is the ability to go through the files and get them organised for further coding.

In this example we have a file name pattern of ModuleCode - Tutor Name - Group Number for example ABC - Jane Doe - Grp 02. So we want to collate all of the files that belong to Jane Doe first, then move on to the next tutor (Micky Mouse in this example).

 The collated data will look like this:

{"Jane Doe":["FILE ID HERE","FILE ID HERE","FILE ID HERE"],"Micky Mouse":["FILE ID HERE","FILE ID HERE"]}

Files to loop through and organise
Files to loop through and organise

Tuesday, 3 January 2023

Bulk add files to existing Google Drive folders

The following Google Apps Script tool is designed to take a Google/Shared Drive folder full of files that you want to make a copy of and place into another set of existing Drive folders.You can decide if you want the subfolder name appending/prepending/ignoring in the file name of the new copy to help make it unique.

The tool will iterate through a single level of folders (not sub-subfolders) and for each one place a copy of the files into it.

Complete the information on the 'Welcome' sheet to set the tool up.
Bulk add files to existing Google Drive folders

Tuesday, 20 December 2022

Sort through an array of duplicates

The following Google Apps Script is designed to go through an array of values that contains duplicates and create a new array of only the unique ones, arranged alphabetically. I needed this code when looping through files in a Google Drive folder where tutors and their groups formed part of the filename that I needed to extract for the end file that was created.

Remove array duplicates
Remove array duplicates

Tuesday, 6 December 2022

Bulk combine CSV files into a single Google Sheet

The following Google Apps Script is designed to take a number of CSV files (structured in an identical way) stored in a Google Drive folder and combine them all into a single Google Sheet file. It maps the data within the CSV file to specific cells in the Google Sheet, along with creating a tab for each of the CSV files to separate them out.

This blog post is a development of my previous one on importing CSV data into (multiple) Google Sheet files.

Bulk combine CSV files into a single Google Sheet
Bulk combine CSV files into a single Google Sheet

Tuesday, 22 November 2022

Filter a try/catch error message

The following Google Apps Script is designed to exercise how you might go about searching the error message in a 'try/catch' for keywords. I wanted this specifically for a tool I built that contains a lot of code (and hence a lot of potential error messages) between a try/catch, for which a very small number of people were experiencing a timezone issue with their Google Sheet file.

The aim was to use a JavaScript 'match' to find the keyword timezone and display a set of instructions for the user to resolve the issue themselves instead of just a generic error message. The below Apps Script code is a simplified version of all of that aimed at just getting a file and using a typo in the code to trigger an error.

Filter an error message in a try/catch
Filter an error message in a try/catch

Tuesday, 8 November 2022

Bulk convert Google Sheets to PDFs

As of February 2023 'Convert Drive Files' is now available as a Google Workspace Marketplace Add-on.

The following Google Apps Script tool is designed to bulk convert all Google Sheets (only) within a given Google Drive folder into PDFs. You can choose the destination folder for the PDFs to be put into and also whether you want the original Sheets to be deleted.

Bulk convert Google Sheets to PDFs using Apps Script
Bulk convert Google Sheets to PDFs using Apps Script

Tuesday, 11 October 2022

Import CSV data into Google Sheet files

The following Google Apps Script is designed to loop through a folder of CSV files in Google Drive, extract the data, create a Google Sheet file per CSV, and insert the data into specific rows/columns.

CSV File template to copy data into
CSV File template to copy data into

Tuesday, 27 September 2022

Get Qualtrics Survey details

The following Google Apps Script is designed to connect to the Qualtrics API for getting the details of a Survey with a given ID, such as its name and the questions.

Qualtrics API Survey details
Qualtrics API Survey details