| Screenshot of spreadsheet with data and Doc link |
I'm Phil Bainbridge and I aim to share my experiences of IT projects I've worked on as I continue to learn and develop, through this blog. My main coding language is Google Apps Script (with JavaScript), but there is also some: PowerShell, HTML, SQL and jQuery.
Tuesday, 19 May 2020
Create Google Doc from Form submission
Tuesday, 12 May 2020
Create a Shortcut in Google Drive
| Screenshot of Shortcut file in Google Drive |
Tuesday, 5 May 2020
Bulk extract text from Google Docs for analysis
| Screenshot of Doc Analysis results in spreadsheet |
Tuesday, 28 April 2020
Create a copy of a file using try/catch
We start by getting the template file that we want to make a copy of but wrap this within a try/catch. As part of getting the file we include an additional variable (gotTemplateFile) set to either true or false depending upon success, which we can then use to determine if the script should proceed with the next step. We also make use of the logEvent Function to output any errors messages:
try {
// get template file
var templateFile = DriveApp.getFileById(templateFileId);
var gotTemplateFile = true;
}
catch(e) {
logEvent('Problem with template file, error: ' + e);
var gotTemplateFile = false;
}
Tuesday, 21 April 2020
Drive API - share a file without email notification
Enable Drive API
In Script Editor go to Resources > Advanced Google services ... > scroll down and turn on Drive API > click OK.
The Code
First we create an array of objects that defines 3 items: value, type and role. These details will form the 'permissions resource':
var resource = {
// enter email address here
value: 'user@example.com',
// choose from "user" or "group" if using a Google Group
type: 'user',
// choose from: "owner", "writer" or "reader"
role: 'writer'
};
Tuesday, 14 April 2020
Google Form - use a switch to determine save location
The example here is a stripped down version that uses colours to determine which Google Drive folder ID should be selected from the Config sheet for the script to proceed. I have another example of the 'switch' process in this blog post on getting a weekday name from a date.
| Screenshot of Google Form question |
Tuesday, 7 April 2020
Bulk change ownership of Google Drive items
The following Google Apps Script is designed to bulk transfer ownership of Google Drive files/folders by iterating through them. It gets the current owner and compares that to the new designated owner before making the change. This particular example will retain the previous owner as an editor of the item.
Update 08/03/2023
Unfortunately this tool no longer appears to work for Consumer accounts, only Workspace ones, due to changes in a user needing to accept a request to transfer ownership. Stack Overflow page with some further details.
| Screenshot of transfer tool requirements |
Tuesday, 31 March 2020
Google Drive Picker for Folder ID
![]() |
| Screenshot of Google Picker in Drive |
