I have a script on Google Sheets that is scheduled to run hourly. The script runs successfully sometimes but it fails with a #NAME? error other times.
All the script does is copy a value in a cell and appends that to a list of values previous values. The problem is that the copied cell is populated from a website API via a JSON call. I think I need a way for the first script to wait until the cell is populated but don't know how.
function recordHistory() {
SpreadsheetApp.flush();
Utilities.sleep(99000); //just trying a long wait to see if that works
var ss = SpreadsheetApp.getActiveSpreadsheet();
var portfolioSheet = ss.getSheetByName("Portfolio");
var historySheet = ss.getSheetByName("Portfolio History");
var data = [
Date(),
portfolioSheet.getRange('C36').getValue(),
portfolioSheet.getRange('H36').getValue(),
portfolioSheet.getRange('A100').getValue(),
'plaintext'
]
historySheet.appendRow(data);
};
Any thoughts?