G-Suite Script: Send Google Doc to Multiple Student Portfolio Folders

This is a Google Apps script that I use to take handout in my Google drive, make a copy of it to every participant portfolio folder in our program, and rename each file according to the participant’s name. 

(I’m hoping to incorporate more reporting elements into this script in Spring 2020 so that each individual student’s handout file URL gets sent to a Google Sheet owned by the instructor for ease of navigation and review—or, indeed, for ease pasting direct links into Canvas for each individual student!)


Our context

  • We use Google docs to make collaboration and portfolio-keeping easier than it currently is in our LMS (although we’ll change platforms if ever a participant needs to work from a country that blocks GDrive access).
  • This script works for traditional folders as well as for Shared Drives. We use the latter so that our fellowship participants have equal ownership permissions over their portfolios in the long run. Instructors creating portfolios for other contexts—or people who don’t want to open up their “Shared Drives” folder and see dozens of student portfolios—might want to choose another option.

Using the Script

  • For the script to work, you’ll need ownership of the files and folders you’re copying from and to.
  • The duplicated documents will have the same viewing/editing permissions as their parent folder.
  • When you run a script for the first time, you’ll be given some ominous warnings about permissions, but my understanding is that if you make a copy of this script, you’re giving permission to yourself. You’ll own the copy of the Google Apps script in question (not me). More info about Google apps scripts here.

The Script

Option 1: Direct Copy

This link will allow you to make a direct copy of the Google Apps Script of your own. (To do so, click “File –> Make a Copy.”)

Option 2: Copy-Paste

Alternatively, you can open up a new Google apps script document and copy-paste the following into it:

//This script will allow you to make a whole lot of 
//copies of a Google Drive document, rename them according to students' names
//and send those copies to individual students' portfolio folders.

//Be careful of what you change. All of the punctuation below is meaningful for the script to work.


//Step 1: open the target folders for each student in Google Drive.
//You will need editing/creator permissions for each folder you're sending these files to.
//Look at the folder URL. There is a string of letters and numbers at the end of it and that is the folder ID.
//Notice that there are single quotations around the document ID. These quotes are important!

function copyTemplates() {
const myTargets = [
{
name: 'Student Name',
folderId: 'add student folder id here but keep these quotes intact'
}, 
{
name: 'Another Student Name',
folderId: 'Do the same thing with a different folder id here'
}
];

for(var index in myTargets) {
//Step 2: Open the Google Drive document that you want to copy. 
//Look at the URL. There is a string of letters and numbers at the end of it and that is the document ID.
//Copy the document ID and REPLACE it in the line of code below. 
//Notice that there are single quotations around the document ID. These quotes are important!

var originFile = DriveApp.getFileById('Add Folder ID here. Example: 11SsAJ8wTZxcf2JBwsH8fkDeG6DYJGWwEwke__-t2tjU');

var thisTarget = myTargets[index];
var thisFolderId = thisTarget['folderId'];
var thisFolder = DriveApp.getFolderById(thisFolderId);
var thisName = thisTarget['name'];

originFile.makeCopy(thisName + ' - ' + originFile.getName(), thisFolder);
}
}

//Step 3: When you have added the relevant names, folder ids, and original document id info to the script, 
//you will click on the save icon and then go to the Run menu and choose copyTemplates. 
//Authorize the script and copies will be made to your drive.

//With gratitude to Alice Keeler and her "CopyDocs" script for the inspiration.

 


Acknowledgments & Gratitude

  • Michael Kellum was kind enough to sit down with me and help build this script together. I’m very grateful for his help in this.
  • With thanks to Alice Keeler for the inspiration to try using Google Apps Script, and for sharing her Copy Docs script with other educators. I’ve also adapted some of the instructional language that she uses in some of her publicly shared scripts in the code itself above. (Things like “//Be careful of what you change. All of the punctuation below is meaningful for the script to work. “)

Further Exploration

Twitter colleagues urged me to dig into Yagisanatode’s Google Scripts Work as well…

License

Icon for the Creative Commons Attribution 4.0 International License

Tiny Teaching Tools Copyright © by Naomi Salmon is licensed under a Creative Commons Attribution 4.0 International License, except where otherwise noted.

Share This Book