I’ve been working on some custom features for a form made in Google Sheets to generate a pdf of the form and also update the PDF is changes are made and saved from the Sheets document.
My below code runs fine after some trouble shooting on a previous question thread, but the PDF remains unchanged even though I have updated and saved the underlying document and ran the function, with no errors.
Here is my script as it stands:
function replaceFile(theBlob, theFileId)
{
var oldFile = DriveApp.getFileById(theFileId);
Logger.log(oldFile.getId());
try
{
Drive.Files.update(
{ mimeType: oldFile.getMimeType() },
theFileId,
theBlob,
{ supportAllDrives: true }
);
Logger.log(Drive.Files.get(theFileId, {supportsAllDrives: true}).getName());
Logger.log("Success!");
SpreadsheetApp.getActive().toast("PDF Updated With Success");
}
catch (error)
{
Logger.log(error);
SpreadsheetApp.getActive().toast(error);
}
}
function test1 ()
{
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
SpreadsheetApp.flush();
var pdfBlob = spreadsheet.getAs('application/pdf');
replaceFile(pdfBlob,"1ZuftxjH8t6WVKR-sxHl98iywhRPDHnC-");
}
link to previous relevant question:
Overwriting PDF File with Google Apps Scripts Causes Drive App to be unable to locate file