Pages

Tuesday, 14 April 2020

Google Form - use a switch to determine save location

The following Google Apps Script is designed to take a specific option selected on a Google Form and use that to determine where something could be stored. The example it was developed for was Risk Assessments where depending on the type of assessment selected on the Form the generated file was to be saved in a specific Google Drive folder.

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
Screenshot of Google Form question

The switch iterates through each case to determine a match against the colour selected from the Google Form. If one is found it then updates the parentFolderId variable with the value from the Config sheet. This can then be used to get the relevant folder and proceed with the rest of the script:
var parentFolderId = '';
switch (colour[0]) {
    case 'Red':
      parentFolderId = redFolderId;
      break;
    case 'Blue':
      parentFolderId = blueFolderId;
      break;
    case 'Green':
      parentFolderId = greenFolderId;
      break;
  }

Google Form - use a switch to determine save location

No comments:

Post a comment