1

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;
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
user2600959
  • 229
  • 4
  • 12

1 Answers1

1

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

Community
  • 1
  • 1
Daniel Wren
  • 290
  • 1
  • 14
  • I changed the name of the function to onEdit(), but still nothing. To test I make a change in the spreadsheet (e.g. cross something out or at text to an empty cell) and check the cell where the function call resides to see if the number changes. The function counts over one column to see if the text is crossed-out, and it works fine only if I open the script and explicitly save it. Otherwise it never updates no matter how many words I cross out in the column. – user2600959 Jul 19 '13 at 21:41
  • The next thing I would try would be to try to isolate if the trigger is firing at all or if a piece of my code is whacking it out. Write messages to the log using: Logger.log("Foo"); to find out if it's firing at all. If so, find out where it stops executing in your code. – Daniel Wren Jul 19 '13 at 21:45
  • Yes it does appear that the edits are causing the trigger to work as the log is getting updated continuously. So it must be my code... what line could it be? – user2600959 Jul 19 '13 at 21:56
  • There may be better ways to do it, but you can move that logging statement through the code to find out where it stops displaying. Or, you can have many, like Logger.log("Got here! - 1"), Logger.log("Got here! - 2"), etc. This helps you isolate the line where it chokes. If you weren't using a Trigger to execute, I'd suggest you use the Debugger instead, as it's quite helpful; I don't think you can use it for this though. The other thing I'd note is that the function is passed in an event object. Access via e.source instead of your first line. Read more here: http://goo.gl/6QytB – Daniel Wren Jul 20 '13 at 01:09