Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

When uploading a file on Google Forms, I would like the file uploads to go into a custom folder based on the form response (their name)

$
0
0

Ex. someone submitting the form with a file upload and on form submit it creates a custom folder based on their form response (their name) on google drive with their submission in it.

Using this script, I can put all files into one folder, but I don't know enough about script to know where to change what the folder is named

const PARENT_FOLDER_ID = "<<Folder ID here>>";const initialize = () => {  const form = FormApp.getActiveForm();  ScriptApp.newTrigger("onFormSubmit").forForm(form).onFormSubmit().create();};const onFormSubmit = ({ response } = {}) => {  try {    // Get a list of all files uploaded with the response    const files = response      .getItemResponses()      // We are only interested in File Upload type of questions      .filter(        (itemResponse) =>          itemResponse.getItem().getType().toString() === "FILE_UPLOAD"      )      .map((itemResponse) => itemResponse.getResponse())      // The response includes the file ids in an array that we can flatten      .reduce((a, b) => [...a, ...b], []);    if (files.length > 0) {      // Each form response has a unique Id      const subfolderName = response.getId();      const parentFolder = DriveApp.getFolderById(PARENT_FOLDER_ID);      const subfolder = parentFolder.createFolder(subfolderName);      files.forEach((fileId) => {        // Move each file into the custom folder        DriveApp.getFileById(fileId).moveTo(subfolder);      });    }  } catch (f) {    Logger.log(f);  }};

Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>