Search code examples
google-apps-scriptgoogle-sheetsgoogle-sheets-formula

Refresh automaticatlly the connection with plx on google sheets


I have a worksheet in google sheets that I'm connecting with plx.

I'd like for an adivse, I want to refresh the date connected with the database everyday at 10am

I know that inside google sheets that we can be able to create triggers and set a specific to work.

About the adise, is it better to only use the function refreshData() with the triggers, or use the entire code that include the Trigger

function setTrigger() {

scheduledTrigger(10,00);
}

function scheduledTrigger(hours,minutes){  
ScriptApp.newTrigger("refreshData")
  .timeBased()
  .atHour(hour)
  .nearMinute(minute)  
  .everyDays(1) 
  .create();
}

function refreshData() { 
var spreadsheet = SpreadsheetApp.getActive(); 
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Data_TAT'), true); 
SpreadsheetApp.enableAllDataSourcesExecution(); 
spreadsheet.getCurrentCell().getDataSourceTables()[0].refreshData();
};

Sorry if I'm not clear


Solution

  • The answer to this question is on the comments by @Cooper:

    It's better to create only one trigger. How you do it is your choice. If your going to do it with script then you should check to see that there is not one already created for a given function.