Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing onEdit trigger in Google Apps Scripts

My colleague and I are teachers and do not have much background in programming. We have pieced together a script that creates a Google Calendar event from a Form fed spreadsheet; however, we cannot get the trigger to work.

Many have suggested moving away from time-based triggers because they can be unreliable, so we'd like to write our own trigger. After researching, it seems an onEdit(e) trigger would be best, but we can't get it to work conditionally. We'd like our script only to run if the approval column says "Yes" (column 13).

From what I've seen, it looks like we should probably be doing this completely differently (maybe with getValue), so I'm calling on everyone here for help. It seems like it should be so simple! FYI, findRow works and makes the calendar events, so we just need findRow to run if column 13 is "Yes."

Any help you can give is greatly appreciated. Here is the code:

function onEdit(e) {
    var range = e.range;
    var colToCheck = 13;
    if (colToCheck = "Yes");
    findRow;
};
like image 602
Mina Marien Avatar asked Jun 05 '26 12:06

Mina Marien


1 Answers

I don't know what findRow() does. But I think this is what you were trying to accomplish.

function onEdit(e)
{
  var ss= e.source;
  var sht=ss.getActiveSheet();
  var range = e.range;
  var row = range.getRow();
  var approval = sht.getRange(row,13).getValue();
  if (approval=="Yes")
  {
    findRow();
  }
}

By the way when I first started studying triggers, I wrote a routine that made a log entry every time I got a trigger and after exactly three days of one hour triggers I had 72 log entrees so I would say that they are very reliable.

like image 174
Cooper Avatar answered Jun 08 '26 00:06

Cooper