“正在编辑”会触发多个电子邮件回复
我有一个代码,一旦W列中填充了电子邮件地址(当有人在同一行中编辑U列时发生),该代码就会发送电子邮件。这是一个“编辑中”触发器。但是,当我在Y列中输入内容时,它会发送另一封相同的电子邮件。我了解这可能是因为触发器处于“正在编辑”状态,并且正在响应该行中的编辑,但是如何使它仅在W列发生变化的情况下才发送电子邮件?
function confirmation() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var responses = spreadsheet.getActiveSheet();
var range = responses.getActiveCell();
var relevantRow = range.getRow()
responses.getRange(relevantRow,22).setFormula('=if(U'+relevantRow+'="","","Changes Made")');
responses.getRange(relevantRow,23).setFormula('=if(U'+relevantRow+'="","",C' + relevantRow + ')');
var email = responses.getRange(relevantRow,23).getValue();
var user = responses.getRange(relevantRow,2).getValue();
var emailBody = 'Hi' + ' ' + user + '\n\nThe online banking request you have submitted has been approved, and all necessary changes have been made. Please check and make sure that you are having no issues. If you are still having issues, please reach out to the appropriate bank admin email box. \n\nAPAC: APAC.bankadmin@nielsen.com \nEMEA: EMEA.bankadmin@nielsen.com \nNAM/LATAM: NAM.bankadmin@nielsen.com. \n\nThank you, \nNielsen Corporate Treasury';
var subject = 'Online Banking Request Completed'
MailApp.sendEmail(email, subject, emailBody) ;
}
答案 0 :(得分:1)
function onEdit(e){}具有e(事件)参数。您可以考虑使用e.range成员来检查编辑操作在何处进行。
if (e.range.getColumn() == 23) { // W column is 23-th
// do something
}
只有编辑了W列中的一个单元格,任何执行“执行操作”的代码都会被触发。