r/GoogleAppsScript • • Jun 17 '20

Question How to refresh IMPORTRANGE values without manually accessing the Sheet itself?

I have an email script that sends an email every morning based on values in a table on the Sheet. Thing is, those values are linked to the Sheet from a data dump sheet elsewhere, and brought in using various =IMPORTRANGE() formulae. What I am noticing is that since no one accesses the Sheet that the script is built in, the email is sending the previous day's values instead of the recently updated values. I suspect this is because the actual cell values in the IMPORTRANGE isn't refreshing to reflect the latest data available, presumably bc Google didnt expect a need for data to refresh if no one is looking physically at the Sheet.

Is there a way to force the refresh of a Sheet via Apps Script or other Sheet settings?

8 Upvotes

2 comments sorted by

6

u/lordph8 Jun 17 '20

I think you want .flush().

SpreadsheetApp.getActive().flush();

1

u/AmnesiaInnocent Jun 17 '20

Well, you can update a cell's formula programmatically, if that's what you're asking...