Google-sheets – Does IMPORTDATA() refresh when an Apps Script runs even if the sheet isn’t open

google sheetsgoogle-apps-scriptimportdata

We have a Google Spreadsheet that pulls data from an external source via an IMPORTDATA() function and then a Google Apps Script that is on a timed trigger that performs other things with the imported data.

It's failed a few times which makes us wonder whether the IMPORTDATA() function is refreshing the data if the sheet is not manually opened? Or in other words when the Apps Script fires from it's timed trigger does the sheet automatically refresh it's formulas?

Best Answer

The IMPORTDATA() function has a latency of approximately 1 hour, as explained in this post on the Google Product Forum.

You mentioned the fact that a script was being fired by a time based Google Apps Script trigger. I was thinking, if you're using a script in the first place, why not fetch the CSV file as well, like so:

Code

var url = 'url to public CSV file';
var text = UrlFetchApp.fetch(url).getContentText();
var csv = Utilities.parseCsv(text);

The var csv is turned into a 2d-array and can be used like any other array. This way, you always have the latest CSV file.

References