Reputation: 195
I have a Google sheet that I am exporting as a PDF using a script. Since I would like to run this weekly and additional entries may be made before exporting to PDF, I would like to run a sort function to ensure that the export PDF is in chronological order. When I added a sort and run the script, I see the sheet update from the sort and then receive the PDF by email, but the PDF is from before the sort.
Is there anyway to delay the rest of the script after I run the sort? Does anyone have another idea to solve this problem?
function ZIP_PDF_EMAIL() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('Project Tracking');
//call sort function
sort(s);
//remainder of pdf export code
Upvotes: 0
Views: 136
Reputation: 46802
You can use the spreadsheet method spreadsheetApp.flush()
that is documented here and updates the whole sheet so that all pending changes are made right away
Upvotes: 1