I'm trying to save a single-sheet spreadsheet to pdf. Many blogs explain how to do this using getBlob() so I ended up with this:
var theBlob = jobSpreadSheet.getBlob().getAs('application/pdf');
var newFile = getPdfFolder().createFile(theBlob.setName(fileName + ".pdf"));
To create jobSpreadSheet I have created a new spreadsheet:
var tempSpreadsheet = SpreadsheetApp.create(name);
var driveTempFile = DriveApp.getFileById(tempSpreadsheet.getId());
var jobsFolder = getJobsFolder();
var driveNewFile = driveTempFile.makeCopy(name, jobsFolder);
var jobSpreadsheet = SpreadsheetApp.open(driveNewFile);
Next I copy a template into the new spreadsheet and remove the empty first sheet:
var jobCard = jobCardTemplate.copyTo(jobSpreadSheet).setName('Job Card');
jobSpreadSheet.deleteSheet(jobSpreadSheet.getSheets()[0]);
Then I update a few cells in the jobCard and finally create the pdf. All the steps work except creating the pdf. The pdf is created, it contains the template, but not the updated values. Should I make the create pdf step somehow wait for the updates to be saved?