I'm trying to export a Google sheet to PDF (that's working) and save it to a Shared Drive. The last part isn't working. I'm able to save it to a Folder on the Google Drive itself, but nog on a Shared Drive.
Probably not the best code ever written, but if you could see beyond my inability to produce something more elegant. I would be thankfull for any good tips!
Kindest regards,
This works
function SaveAsPDF() {
var sheetname = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
var sheetn = SpreadsheetApp.getActive().getSheetByName(sheetname);
const folderName = `typfoldernaam`;
const nameFile = "test_" + sheetn.getRange('B3').getValue().toString() +".pdf"
DriveApp.getFoldersByName(folderName)
.next()
.createFile(SpreadsheetApp.getActiveSpreadsheet()
.getBlob()
.getAs(`application/pdf`)
.setName(nameFile));
}
Above code writes a PDF to a folder on my Google Drive
The code below doesn't work. It should just make a copy of the current sheet and save it to the shared drive:
function copytoMyDrive(){
var sApp = SpreadsheetApp.getActiveSpreadsheet();
var destinationMyDriveId = "ID1234567890";
var sourcesheet = sApp.getSheetByName("testsheet");
Drive.Files.copy({title:'Copy of file', parents:[{id:destinationMyDriveId}]}, sourcesheet, {supportsAllDrives: true})
This last one gives me following error: GoogleJsonResponseException: API call to drive.files.copy failed with error: Required
I'm also aware that the last piece of code does not produce a PDF but will simply make a copy. So that would have to be addressed as well...