我在理解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("[email protected]");
         } //.....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()触发器发送电子邮件。在受限制的文档here中,甚至给出了示例


他们无法访问需要授权的服务。例如,简单触发器无法发送电子邮件,因为Gmail服务需要授权,但是简单触发器可以使用语言服务(匿名)翻译短语。

08-26 04:34