Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

too many emails getting triggered from google script

I am trying to trigger an email each time a row is updated on a google sheet. However too many emails are getting triggered when 1 row is being added. The Code I am using is below.

`

function valueCheck(e) {
  var ss= SpreadsheetApp.getActive();
  var sheet1= ss.getSheetByName("Applications");
  var lastRow = sheet1.getLastRow();
  var companyName = 2;
  var applicationLink=3;
  var com = sheet1.getRange(lastRow, companyName).getValue();
  var link1= sheet1.getRange(lastRow, applicationLink).getValue();
  if (link1)
  {
    MailApp.sendEmail("r***@gmail.com","Apply to "+com,"link to apply:"+link1);
}
}
question from:https://stackoverflow.com/questions/65911465/too-many-emails-getting-triggered-from-google-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try something like this:

function onMyChange(e) {
  const sh=e.source.getActiveSheet();
  //e.source.toast('Entry');//for debugging
  //sh.getRange('A1').setValue(JSON.stringify(e));//You use this to learn more about the event object
  if(sh.getName()=='Sheet1' && e.changeType=="EDIT") {//I assume you're using EDIT changeType
    //e.source.toast('Sheet1')//for debugging
    //do your stuff in here
  }
}

I don't know what changeType you want to use.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...