Hi all,
I'm attempting to automate the pulling of tables from my company's Looker instance into Google Sheets using time-based triggers, but I'm having a bit of trouble. I found a script on Looker's website that I'm using to import these files, as follows:
function lookerFetchData(url) {
url = url.replace(/(\/\w+\.)txt|html|csv|gsxml(\?.*)?/, "$1csv$2");
var csvString = UrlFetchApp.fetch(url).getContentText();
var dataIn = Utilities.parseCsv(csvString);
var dataOut = dataIn.map(function(row) {
return row.map(function(val) {
if (val == '') return '';
var dateMatch = /(\d{4})\-(\d{2})-*(\d{0,})/.exec(val);
while (dateMatch != null) {
// first index is full match
return new Date(dateMatch[1], dateMatch[2] - 1, dateMatch[3] || 1);
};
if (val.match(/[-a-zA-Z]/)) {
return String(val)
};
val = val.replace(/[^\d.]/g, '');
if (val.match(/[0-9.]+/))
return Number(val);
return Number(parseInt(val));
});
});
return dataOut;
}
I then added a time-based trigger to have this script run once daily in one of my sheets. However, when it ran, this error was sent to me via email:
TypeError: Cannot find function replace in object {year=2020, month=2, day-of-month=13, day-of-week=4, week-of-year=7, hour=5, minute=56, second=31, timezone=UTC, authMode=FULL, triggerUid=3099827}. (line 2, file "Code")
I'm not sure exactly what the error is asking for - I see a url.replace function within the larger function already. Can somebody help me troubleshoot?
Thanks,
Aaron