I have a connected sheet that has results of a bigquery query(extract sheet). I created a preview of the results sheet. How do i write an appscript fuction to refresh the results in the extract and preview sheets? Please help.
I tried to use this code to refresh the connected sheet query , but it gave me an error saying : "Exception: The data object does not exist." I would like to write an apps script function if possible.
function refresh() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('A1').activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('test'), true);
  SpreadsheetApp.enableAllDataSourcesExecution();
  spreadsheet.getCurrentCell().getDataSourceTables()[0].refreshData();
  //DriveApp.getFiles()
};

 
     
    