[英]Google Apps Script - Using onEdit to run script if cell = 'yes'
我在理解Google Apps脚本中的onEdit()函数时遇到麻烦。
我有一个Google表格,该表格具有一个“主”标签和4个单独的标签,如果用户在任何一个单独的表格的“发送电子邮件”列中选择“是”,我都需要它来发送电子邮件。 我有一个函数可以完美地完成此任务,在调试器中,我将其粘贴到此处:(我知道它可能可以简化/缩减:)
码:
function triggers() {
//Hold all values of selected sheet
var zy = holdingData.values;
for (var j = 0; j < zy.length; ++j) {
//Get the UI functions and store them in a variable, used for prompts later in the script
var ui = SpreadsheetApp.getUi();
if (zy[j][9] === 'Yes') {
//Pull values for later use
holdingData.selVals.push([zy[j][0], zy[j][1], zy[j][2], zy[j][3], zy[j][4], zy[j][5], zy[j][7], zy[j][23], zy[j][24], zy[j][25]]);
//Pull Teacher email from Master column B
holdingData.teacherEmail.push(holdingData.selVal[j][7]);
//Assign email based on contents of column X
if (holdingData.selVals[j][8].toLowerCase() === "miranda") {
holdingData.counselorEmail.push("FakeEmail1@Madeup.com");
} //.....Other cases after this, cut for length
//Assign subject line for specified individual
holdingData.subject.push("Referral: " + holdingData.selVals[j][0] + " " + holdingData.selVals[j][1]);
//Store columns C,D, and E in 1 variable string for each student
holdingData.actionsTaken.push(holdingData.selVals[j][2] + ", " + holdingData.selVals[j][3] + ", " + holdingData.selVals[j][4]);
//Assign Email message contents for specified individual sheet
holdingData.message.push("The referral submitted for " + holdingData.selVals[j][0] + " " + holdingData.selVals[j][1] + " has been completed. The following action(s) were taken: " + holdingData.actionsTaken[j] + ", Please email the member of the discipline team who handled the referral if you have any questions or concerns, at: " + holdingData.counselorEmail[j] + ".");
//Prompt user to confirm they would like to send the emails
var response = ui.prompt('Are you sure you would like to send emails to the selected staff memebers?', ui.ButtonSet.YES_NO);
if (response === 'YES') {
//Send Message to Referring teacher
MailApp.sendEmail(holdingData.teacherEmailMir[j], holdingData.subjectMir, holdingData.messageMir);
//Send Message to Counselor assigned to student
MailApp.sendEmail(holdingData.counselorEmailMir[j], holdingData.subjectMir, holdingData.messageMir);
} else {return;}
}
}
}
我删节了一些,但我想做的核心在那里。 如果我把整个东西都包装在一个onEdit()中,那就行不通了。 如果我将OnEdit()用作简单触发器(我相信),则每次编辑任何工作表时都会触发此脚本。 我尝试了其他一些方法,但是没有运气。 我没有得到什么? :)
没有任何反应,因为您尝试使用简单的onEdit()
触发器发送电子邮件。 在受限制的此处文档中,甚至给出了示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.