基于特定列中的任何文本触发电子邮件

huangapple go评论83阅读模式
英文:

Trigger Email based on any text in Specific Column

问题

尝试在列C中放入任何内容时触发发送电子邮件。使用当前的脚本,只有在我在任何行的列C中放入"TEST"时才能正常工作。我需要它在任何行的列C中放入任何内容时触发。是否有一种通配符可以表示任何输入?

function sendMailEdit(e) {
  if ((e.range.columnStart != 3 || e.value != "TEST")) return;
  const rData = e.source.getActiveSheet().getRange(e.range.rowStart, 1, 1, 4).getValues();
  let job = rData[0][1];
  let req = rData[0][0];
  let item = rData[0][2];
  let now = new Date().toLocaleString("en-US");
  var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Requestors").getRange("B2:B");
  var emailAddress = emailRange.getValues();
  
  let msg = "Job # = " + job + " \nRequestor = " + req + " \nItem Requested = " + item + "  \nDate & Time Requested " + now;
  Logger.log(msg);
  GmailApp.sendEmail(emailAddress, "Raw Material Request", msg);
}
英文:

Trying to trigger to send email when anything is put into column C. With currect script it will work just fine if I put TEST in any row column C works great. I need it to trigger if anything is put into anyrow column C. Is there a wildcard so to speak for anything entered?

function sendMailEdit(e){
  if ((e.range.columnStart != 3 || e.value != "TEST")) return; 
  const rData = e.source.getActiveSheet().getRange(e.range.rowStart,1,1,4).getValues();
  let job = rData[0][1];
  let req = rData[0][0];
  let item = rData[0][2];
  let now = new Date().toLocaleString("en-US");
   var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Requestors").getRange("B2:B");
    var emailAddress = emailRange.getValues();
  
  let msg = "Job # = " + job + " \nRequestor = " + req + " \nItem Requested = " + item + "  \nDate & Time Requested " + now;
  Logger.log(msg);
  GmailApp.sendEmail(emailAddress, "Raw Material Request", msg) 
}

答案1

得分: 0

关于您对“我需要它在将任何内容放入任何行的C列时触发”的期望结果,在这种情况下,可以考虑使用isBlank()。 当这反映在您的脚本中时,请按以下方式进行修改。

从:

if ((e.range.columnStart != 3 || e.value != "TEST")) return; 

到:

if (e.range.columnStart != 3 || e.range.isBlank()) return; 

通过这样做,当将值放入“C”列时,将运行if语句下面的脚本。

参考链接:

英文:

About your expected result of I need it to trigger if anything is put into anyrow column C., in this case, how about using isBlank()? When this is reflected in your script, please modify it as follows.

From:

if ((e.range.columnStart != 3 || e.value != "TEST")) return; 

To:

if (e.range.columnStart != 3 || e.range.isBlank()) return; 
  • By this, when a value is put into column "C", the script below this if statement is run.

Reference:

huangapple
  • 本文由 发表于 2023年2月24日 04:13:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75549869.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定