AppsScriptPulse

Organise Google Drive files into a JavaScript object for use with Google Apps Script

Organise Google Drive files into a JavaScript Object so that they can be looped through for each named individual.

Files to loop through and organise

Files to loop through and organise

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"
   ]
}

Source: The Gift of Script: Organise files into a JavaScript Object

Bulk add files to existing Google Drive folders using Google Apps Script

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.

Bulk add files to existing Google Drive folders

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.

Source: The Gift of Script: Bulk add files to existing Google Drive folders

Bulk combine CSV files into a single Google Sheet with Google Apps Script

Bulk combine multiple CSV files into a single Google Sheet, putting the data in specific locations and creating multiple tabs.

Bulk combine CSV files into a single Google Sheet

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.

Source: The Gift of Script: Bulk combine CSV files into a single Google Sheet

Get hidden or visible Google Sheet tabs with Google Apps Script

Learn how to list hidden Google Sheets tabs with Google Apps Script – CODE and VIDEO tutorial with script explainers.

This post from Scott Donald is an opportunity to learn about how you can work with hidden tabs in Google Sheets with Apps Script. For beginners this post is also an opportunity to learn about the JavaScript reduce method as a way to iterate through data. As well as the code and supporting video the author Scott Donald has some related projects where you can see this solution in action.

Source: Get Hidden or Visible Google Sheet Tabs with Google Apps Script – Yagisanatode

Tech Recruiter Tries Coding pt. 2 — Google Apps (Type)Script

Image credit: Unknown

Talking CRMs, Databases, and how to ditch them; this time within the Lead Generation domain. Bonus: pitfalls of a 90s computing mindset! 😅

Previously on Pulse we shared Rafael Romo Mulas’ post, Tech Recruiter Tries Coding. Rafael has recently published part 2 in which they highlight their journey into VS Code, clasp and TypeScript. If you are unfamiliar with TypeScript its a language which transpiles into JavaScript and basically designed to help you write better code. Rafael notes:

… the main difference is you are forced to be more precise, which avoids running into stupid errors! Therefore, to my surprise, it is actually easier to code in TypeScript than JavaScript, even more so for a beginner like me, because:

  • There is not much to “unlearn” from JS, if you just started anyway.
  • You’re alerted when values can be of a type that would cause errors.
  • You’re forced to do something about it, basically debugging in advance.

You can read more about Rafael’s journey in the linked article

Source: Tech Recruiter Tries Coding pt. 2 — Google Apps (Type)Script

Filter a try/catch error message when coding with Google Apps Script

Search a try/catch error message for keywords to determine the error message to log using JavaScript match.

Filter an error message in a try/catch

Filter an error message in a try/catch

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.

Source: The Gift of Script: Filter a try/catch error message

Bulk convert Google Sheets to PDFs using Google Apps Script

Bulk convert Google Sheets within a given Google Drive folder into PDFs and optionally delete the original file.

Bulk convert Google Sheets to PDFs using Apps Script

Bulk convert Google Sheets to PDFs using Apps Script

Features

  • Maximum runtime – in order to prevent the tool from reaching the limits imposed by Google you can adjust the number of minutes the tool can run for. Change this in the ‘GlobalVariables.gs’ file in the Script Editor.
  • Continue from where it left off – if you have a lot of Google Sheets to convert and the above runtime is reached the tool will save its progress and prompt you to run it again, avoiding any file duplication.
  • HTML popup – as well as the ‘Log’ sheet the tool displays a direct popup to the user if it encounters a problem.
  • PDF counter – after successfully running the tool will include the number of PDFs created as part of the success popup to the user.

Source: The Gift of Script: Bulk convert Google Sheets to PDFs

Workaround: Checking Existence of File ID in Google Drive without Access token and API key using Google Apps Script

This is a workaround for checking the existence of file ID in Google Drive without both the access token and API key.

When you want to check whether the file of the file ID is existing in Google Drive, generally, you might use Drive API and Drive service (DriveApp) of Google Apps Script. In this case, the scope of Drive API is required to be used. By this, the access token and the API key (in the case of publicly shared files) are required to be used. But, there might be a case that the available scopes are limited. In this post, I would like to introduce a workaround for checking the existence of file ID in Google Drive without both the access token and API key.

This workaround could have been a nice addition to a recent project I was working on to audit a bunch of Google Drive file IDs. As noted in this post a big benefit of the approach is there is no need to include Google Drive authentication scopes to your project. See the source post for the code and explanation.

Source: Workaround: Checking Existence of File ID in Google Drive without Access token and API key

The 5th-year Anniversary of Yagisanatode! A [Google Apps Script Developer Expert] Origin Story

Learn the origin story of a solopreneur, Scott and how he built Yagisanatode over the past 5 years. …

“We had just started the second semester of a university course that I was instructing on and my operations director pulled me out of my first class for the semester within an hour and asked me to teach the advanced course. I lasted a day…”

Continuing on from yesterday’s theme of ‘code zero’ to ‘code hero’ here is another origin story this time from Scott Donald. The EDU sector is a rich vein when it comes to producing ‘noisy’ Google Apps Script developers. There are probably a number of reasons why this sector produces so many of the most impactful community contributors. Education, particularly assessment, is so admin intensive it’s maybe not that surprising that stories similar to Scott’s are quite common, but perhaps the biggest factor is educators like to educate!

Source: The 5th-year Anniversary of Yagisanatode! An Origin Story. – Yagisanatode

Tech Recruiter Tries Coding — Google Apps Script

Photo by Mohammad Rahmani on Unsplash

After years of working adjacent to software development, first in sales and then in recruitment, I abruptly decided to take the plunge into the other side, and start coding to automate or speed up tasks of my everyday job.

The idea came by when I started using Google Sheets more heavily, and realized how powerful it is by itself, and how much more it can become with the addition of Google Apps Script, which I discovered to my surprise is actually modern JavaScript.

Sharing this post as hopefully it’s encouragement if you are new or a beginner to Google Apps Script that with some time and effort you can begin building your custom solutions in Google Workspace. Also, if nothing else it’s all a great reminder that you can quickly enhance your UI with Unicode characters:

Source: Tech Recruiter Tries Coding — Google Apps Script