1
votes

So I'm using a script on my googledoc spreadsheet that goes through a column and counts a certain number of occurrences of specified formatting. (i.e. in my spreadsheet "=myFunction()")

The function works fine, but my problem is despite setting up a trigger to run the script "onEdit", it never does it. I have to open the script up and save it each time I want it to update on my spreadsheet.

I've been looking up for hours but no one seems to have my question. There are no errors sent by the notifications. The code (though I don't think it's terribly relevant) for my function is:

function CountIfNotStrikeThrough2()
{

  var ss = SpreadsheetApp.getActiveSpreadsheet(); 
  var mysheet = ss.getActiveSheet();


  var mydatarange = mysheet.getRange(1,1,390,1);
  var numRows = mydatarange.getLastRow();
  var rowindex = mydatarange.getRowIndex();
  var columnindex = mydatarange.getColumnIndex();

  var total =0;

  for(i=rowindex;i<=numRows;i++)
  {
    if(mydatarange.offset(i-1, columnindex-1, 1, 1).isBlank() != true && mydatarange.offset(i-1, columnindex-1, 1, 1).getFontLine() != "line-through")
    {

      total++;
    }    
  }

  return total;
}
1

1 Answers

1
votes

I know there's a thread here that has a comprehensive list of when the onEdit trigger doesn't activate. (here) For example, if you setup Data Validation and select an item from the list of values in the validation, it doesn't trigger the onEdit function.

Besides that, could you try a simple trigger instead of installable? This is to say, instead of explicitly associating CountIfNotStrikeThrough2() to the onEdit trigger, please try re-naming the function to "onEdit()" instead and see if that works. This creates an implicit or simple trigger. I've had trouble in the past with installable vs. simple triggers.

Also, please share the exact action you're performing to test the trigger.

Reference: https://developers.google.com/apps-script/understanding_triggers