Google Drive – Share Folder with Submitters of Google Form

google sheetsgoogle-drivegoogle-forms

I have a Google Form that is used as a sign up form. This form has a question requesting emails. It uses the email validation. I have a Google Drive folder that I want everyone who signs up to be able to view. Some of these files, I want to be able to easily set it up so they can edit it. How can I do this?

Best Answer

Short answer

This could be done by using Google Apps Script.

Instructions

  1. Open the form editor
  2. Click More (the three dots buttons) > Script editor...
  3. Add the script included below
  4. Click on Resourses > Current project triggers
  5. Click on Add a new trigger
  6. Set the parameters as shown in the following snapshot:

Current project's triggers

  1. Click save.

Script

function onFormSubmit(e) {
  // Set custom parameters (change this)
  var emailQuestionTitle = 'Email';
  var folderId = '0B5xqUTHHK_n6d3pWc2l5dVBWZ1k';
  
  // Get the email
  var itemResponses = e.response.getItemResponses();
  var i = 0;
  try {
    while(itemResponses[i].getItem().getTitle() != emailQuestionTitle){
      i++;    
    }
  } catch(e) {
    Logger.log(emailQuestionTitle + ' not found');
  }
  var emailAddress = itemResponses[i].getResponse();
  
  // Share the folder
  var folder = DriveApp.getFolderById(folderId);
  folder.addEditor(emailAddress);
}