0
votes

I am running a script in google sheets script editor, to trigger the script I use onChange in the Current project's triggers, using specific function -> From Spreadsheet -> On change.

Important to mention that I use the sheet with 3 more members that have edit permission who change time to time the data, I built the script and activate the trigger.

When I change anything in the sheet I get alerted (the trigger were on) but when other member changes the data the trigger doesn't work.

What have I missed here?

Thanks.

1

1 Answers

1
votes

Everyone needs a trigger

You can add the trigger management into the program so that they have the triggers in their projects too. The isTrigger() function insures that you only create one trigger for each instance. You find the documentation here.

function myTriggerSetup() 
{
  if(!isTrigger('functionName'))
  {
    ScriptApp.newTrigger('functionName').forSpreadsheet('Spreadsheet').onChange().create();  
  }
}

function isTrigger(funcName)
{
  var r=false;
  if(funcName)
  {
    var allTriggers=ScriptApp.getProjectTriggers();
    var allHandlers=[];
    for(var i=0;i<allTriggers.length;i++)
    {
      allHandlers.push(allTriggers[i].getHandlerFunction());
    }
    if(allHandlers.indexOf(funcName)>-1)
    {
      r=true;
    }
  }
  return r;
}