0

I am trying to create a trigger that sends emails when lines are appended or inserted to a sheet. The problem I have is that the python script that is connected to the google sheet purges sheet "new_strikes" then inserts new information in the same Google sheet. I have a onChange trigger like so:

function trigFunc(e){
  var activeSheet = e.source.getActiveSheet();
  if(activeSheet.getName() != 'new_strikes') return;
  Utilities.sleep(30);
  sendEmail();
}

The problem is when I purge then insert data into this sheet, the script runs twice--once for the purge and once for the edit. Since the trigger sends an email, I get two emails. How do I modify the code or trigger so that it only tracks the insertion of data and therefore sends one email?

1

Instead of calling trigFunc(e) directly from the on change trigger, add the following function to your project and set your trigger to call it:

function respondToOnChange(e){
  if(e.changeType === 'INSERT_ROW') trigFunc(e);
}

Resources

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.