I am a teacher with limited coding knowledge. I am trying to create a google app script so that my students can upload documents from a form. on the form, the student will choose their name from a droplist and I would like the script to upload the documents in the folder with the same name that I have previously created on my drive.
I found this script which allows uploading the file to a specific folder based on the folder id. How could I modify it to upload to different folder ids based on the name they have chosen on the form?
function myFunction (e) {
var form = FormApp.getActiveForm();
var formResponses = form.getResponses();
var formResponse = formResponses[formResponses.length-1];
var itemResponses = formResponse.getItemResponses();
// I modified below script.
Utilities.sleep(3000);
var folderId = "1dNoanQMGXvBDIsIRITNHCXnP8srW_Wlt"; // Please set folder ID of the destination folder.
var destfolder = DriveApp.getFolderById(folderId);
for (var i = 0; i < itemResponses.length; i++) {
if (itemResponses[i].getItem().getType() == "FILE_UPLOAD") {
var ids = itemResponses[i].getResponse();
for (var j = 0; j < ids.length; j++) {
var file = DriveApp.getFileById(ids[j]);
destfolder.addFile(file);
file.getParents().next().removeFile(file);
}
}
}
}
I got the result I was looking for by adding a switch function to the script. hope it might help others....