0

I am using IMPORTDATA() to pull a CSV from SurveyGizmo that should be updated in realtime when a user submits their survey. While the initial import of the CSV data loads fine, it never seems to update unless I delete the IMPORTDATA function and then paste it back in. I have tried to automate this by setting up a Google Apps Script and a trigger set to run the function on open and every 5 minutes. Here is the script I am using:

function myFunction() {
  // clear the cells
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("realtime").getRange('A1:AP1000').clearContent();

  //give the SurveyGizmo server a delay between requests
  Utilities.sleep(12000);

  // Pull data
 SpreadsheetApp.getActiveSpreadsheet().getSheetByName("realtime").getRange('A1').setValue('=QUERY(IMPORTDATA("https://address-to-csv&realtime=true"), "select * order by Col1 desc")');
}

The &realtime=true is a SurveyGizmo call to refresh the CSV and get the latest data.

I'm not sure if this is an issue with Google, my script, or Survey Gizmo.

Any help or clarification is welcomed!

TheMaster
  • 45,448
  • 6
  • 62
  • 85
acircleda
  • 673
  • 4
  • 13
  • 1
    This question [here](https://stackoverflow.com/questions/56784680/google-script-updating-a-single-cell-with-an-importdata-formula) might help –  May 20 '20 at 16:49

1 Answers1

2

After you clear the cells, add SpreadsheetApp.flush() to force Google Apps Script to apply the changes to the spreadsheet.

Also, replace setValue by setFormula (you could even remove the equal sign from the formula)

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • 1
    I used SpreadsheetApp.flush() and it seems to be performing better, though it is not updating as often as it should. I suspect the issue is SurveyGizmo refusing the update request – acircleda May 21 '20 at 18:51