Home > Software design >  onChange specify tab google sheets
onChange specify tab google sheets

Time:01-13

Is there any way of specify the tab of a spreadsheet when using onChange trigger.

I have a function that is running fine but since there are references and things change in several tabs in my spreadsheet the function fires several times. I tried something like this but it only works for edit and not change.

function Button(e) {
  // Get the sheet where the data is, in sheet 'Notif Inv'
  var sheet = e.source.getActiveSheet();
  if (sheet.getName() === 'Trigger') {

listFolers();
 }

SpreadsheetApp.flush();
  Utilities.sleep(sec*1000);
  SpreadsheetApp.flush();

      FolderMaker();
      createFoldersTasks_();
      createFolderByTask_();
      createFolders_();
      createFolderInFolder_();
      isFolderInFolder_();
 
}

CodePudding user response:

Execute createSpreadsheetOpenTrigger once (onChange is an installable trigger, not onEdit)

Then you will get the name of the sheet where you are changing something. You can then compare to your setting.

function createSpreadsheetOpenTrigger() {
  var ss = SpreadsheetApp.getActive();
  ScriptApp.newTrigger('button')
    .forSpreadsheet(ss)
    .onChange()
    .create();
}
function button(e){
  Browser.msgBox(e.source.getActiveSheet().getName())
}
  •  Tags:  
  • Related