I’m new to Google AppScripts and seem to have hit a wall when trying to change uploaded form name and move it to a Google shared drive.
Users input 8 short answers to a form and attach a file (which all goes into the Responses single sheet)
I have combined the 8 short answers into one name seperated by “-“‘s that I would like to save the uploaded form as and then move this file to the Shared drive.
So, column 1 is time stamp, 2 through 8 are input(combined to column 10), 9 is the uploaded form URL.
I’ve tried several different things like split, Moveto, Getfolder or Getfile by ID using DriveApp but can’t figure it out. Any help would be greatly appreciated. It seems like I would have to pull the fileId from the URL in (Lastrow,9). I can move files to Shared_drive so I have the writes.
function myFunction() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet=ss.getActiveSheet();
var lastRow=ss.getLastRow();
var Lot=sheet.getRange(lastRow,2).getValue();
var Part=sheet.getRange(lastRow,3).getValue();
var Heat=sheet.getRange(lastRow,4).getValue();
var CertDate=sheet.getRange(lastRow,5).getValue();
var Basic=sheet.getRange(lastRow,6).getValue();
var Notes=sheet.getRange(lastRow,7).getValue();
var PO=sheet.getRange(lastRow,8).getValue();
var Cert="Certification";
var newResponse=Cert.toString()+" - "+Lot.toString()+" - "+Part.toString()+" - "+Heat.toString()+" - "+CertDate.toString()+" - "+Basic.toString()+" - "+Notes.toString()+" - "+PO.toString();
sheet.getRange(lastRow,10).setValue(newResponse);
var url=sheet.getRange(lastRow,9).getValue();
var file = DriveApp.getFileById(fileId); //fileId needs to be the uploaded file ID in (lastrow,9 or var url)
var parentFolder = DriveApp.getFolderById(TEAMDRIVEID); // I can put the teamdrive id in here
parentFolder.addFile(file);
// Then I need to remove uploaded file (url) to trash/delete it
}
danwapc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.