脚本编辑器范围故障拍摄

时间:2017-04-20 16:34:18

标签: google-apps-script google-sheets

我差不多完成了编写代码,以便在员工提交截止日期时自动发送提醒电子邮件。但是,我需要帮助确定如何自动将工作人员的姓名插入电子邮件中。

我是编写代码的完全新手,所以我对这个问题的语言有些限制。我通过将事情拼凑在一起并经过反复试验来教会自己。如果需要,这是我的表格的链接:

我在下面发布了我的代码:" msg"我试过写:  var msg ="你好" + staff_info_values +" \ n \ n这提醒您,您的EPICS会议将在一周内到期。\ n \ n如果有任何问题,请随时与我们或您的单位教练联系。"但当然这会返回整个范围的员工价值。

我的整个代码:



function CustomEmail() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[0]);
var sheet = spreadsheet.getActiveSheet();
var lastRow = sheet.getLastRow();
var startRow = 2;
//range of days left
var range = sheet.getRange(2,3,lastRow-startRow+1,1 );
var numRows = range.getNumRows();
var days_left_values = range.getValues();
//range of staff names  
range = sheet.getRange(2, 1, lastRow-startRow+1, 1);
var staff_info_values = range.getValues();
//range of emails
range = sheet.getRange(2, 2, lastRow-startRow+1, 1);
var staff_info_email = range.getValues();
//range of coach emails
range = sheet.getRange(2, 4, lastRow-startRow+1, 1);
var coach_info_email = range.getValues(); 
//range of cjm1 emails
range = sheet.getRange(2, 5, lastRow-startRow+1, 1);
var cjm1_info_email = range.getValues();
//range of cjm2 emails
range = sheet.getRange(2, 6, lastRow-startRow+1, 1);
var cjm2_info_email = range.getValues();
//range of FTO emails
range = sheet.getRange(2, 7, lastRow-startRow+1, 1);
var fto_info_email = range.getValues();
//range of EPICS Lead emails
range = sheet.getRange(2, 18, lastRow-startRow+1, 1);
var epics_lead_info_email = range.getValues();
 
var warning_count = 0;  
var msg = "Hello,\n \nThis is a reminder that your EPICS session is due in one week.\n \nPlease don't hesitate to contact us or your unit coach with any questions.";
var msg2 = "Hello [insert staff name],\n \nThis is an automated message from the EPICS unit. \n \nAccording to records, your EPICS coaching session is two weeks overdue. Please schedule a session with your coach to be removed from overdue status. \n \nPlease advise if you feel you have received this notification in error.";
var msg3 = "This is an alert for the EPICS Lead Officer that [insert staff name] is two months overdue for a session."
  for (var i = 0; i <= numRows - 1; i++) 
  {
    var days_left = days_left_values[i][0];
    if(days_left == 7) 
    {
      var reminder_name = staff_info_values[i][0];
      var emailaddress = staff_info_email[i][0];
      MailApp.sendEmail(emailaddress, "EPICS Session Reminder", msg);
      Logger.log(msg);
    }
    if(days_left == -14) 
    {
      var reminder_name = staff_info_values[i][0];
      var emailaddress = staff_info_email[i][0];
      var coachaddress = coach_info_email[i][0];
      var cjm1address = cjm1_info_email[i][0];
      var cjm2address = cjm2_info_email[i][0];
      var ftoaddress = fto_info_email[i][0];
      MailApp.sendEmail(emailaddress + "," + coach_info_email + "," + cjm1_info_email + "," + cjm2_info_email + "," + fto_info_email, "EPICS Session Overdue Reminder", msg2);
      Logger.log(msg2);
    }
    if(days_left == -60) 
    {
      var reminder_name = staff_info_values[i][0];
      var leadaddress = epics_lead_info_email[i][0];
      MailApp.sendEmail(leadaddress, "EPICS Session Alert", msg3);
      Logger.log(msg3);
    }
  }   

} 
&#13;
&#13;
&#13;

0 个答案:

没有答案