-1

I wanted to execute a function whenever a cell is edited or added in google spreadsheet.

I have the below function, but it is not working. please help. Also I wanted to call the function Start sync after X seconds. How to give a delay in calling the startSync()

function onEdit(e) {

  var range = e.range;
  range.setNote('Last modified: ' + new Date());
  startSync()
}

whenever I edit a cell , a note (comment) is getting added to the cell , but the startSync is not getting called.

function startSync() {
  //Get the currently active sheet
  var sheet = SpreadsheetApp.getActiveSheet();
  //Get the number of rows and columns which contain some content
  var [rows, columns] = [sheet.getLastRow(), sheet.getLastColumn()];
  //Get the data contained in those rows and columns as a 2 dimensional array
  var data = sheet.getRange(1, 1, rows, columns).getValues();

  syncMasterSheet(data);
}

Answer: Installable Triggers helped me to call StartSync()

  • What services does the `startSync` call stack invoke? If any require authorization - such as opening a different spreadsheet document - then you cannot use a simple trigger. – tehhowch Apr 15 '18 at 04:01

1 Answers1

-1

You can't use a simple onEdittrigger with most .set methods. You need to use an installed onEdit() trigger instead. See this answer for more information on triggers

To delay the start of the function use Utilities.sleep(milliseconds) before the call to the startSync() function. See more info about the Utilities class here

James D
  • 3,102
  • 1
  • 11
  • 21