Проблемы с получением дубликатов электронных писем - PullRequest
0 голосов
/ 14 мая 2019

У меня проблема с моим сценарием, более конкретно, когда кто-то отправляет форму, я получаю электронное письмо с вопросами, после чего группа (включая меня) получает электронное письмо с вопросами и ответами. Поэтому я, как создатель формы / таблицы, получаю два электронных письма, когда форма заполнена.

Я включил приведенный ниже код ... любая помощь с благодарностью !!

Ничего еще !! Помогите !!

function onFormSubmit(e) {

  var eTimestamp = e.values[0];
  var eDept = e.values[1];
  var eRequest = e.values[2];
  var eUrgent = e.values[3];
  var eName = e.values[4];


  var currDept = eDept;

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet1= ss.getSheets()[0];   //sheet1 (where the form data goes)
  var sheet2 = ss.getSheets()[1];  //email data
  //    var lastRow = sheet1.getLastRow();

  //var currDept = "Traffic Dept";

  // *** Create the email recipient list
  var rcptvals = sheet2.getRange(2, 1, 101, 1).getValues();
  var toWhom = "";
  for (var i = 0; i < 100; ++i) {  //This is the number of rows to include on the email
    toWhom = toWhom + rcptvals[i][0] + ",";
  }

  //**********************************************************************************************************
  //*** Based on the dept, determine who else needs to be included in the email and create the email list. ***
  //**********************************************************************************************************
  // The maximum number of groups is capped at 99.
  var emailGroup = "";
  var groupToEmailRange = sheet2.getRange("C1:D100"); //max number of groups is 99
  var groupToEmail = groupToEmailRange.getValues();

  // check to see who to add to the email list based on the department
  for (var groupNum = 1; groupNum <= 99; ++groupNum) {
    if (groupToEmail[groupNum][0] == currDept) {            //find the matching department
      emailGroup = groupToEmail[groupNum][1];               //get the dept mgmt group email addresses from col 2 of the dept info
    }
  }  
  // Include additional people in the email based on the department in the email list
  //toWhom = toWhom + "," + submitter + "," + emailGroup;   
  toWhom = toWhom + "," + emailGroup;   

  //toWhom = "example@gmail.com";

  Logger.log(toWhom);
//}

//function EmailGoogleFormData(e) {

  if (!e) {
    throw new Error("Please go the Run menu and choose Initialize");
  }

  try {

    if (MailApp.getRemainingDailyQuota() > 0) {

      // You may replace this with another email address
      var email = "example@gmail.com";      


      // Enter your subject for Google Form email notifications
      var subject = (" Maintenance Work Order Request For") + eDept;

      var key, entry,
        message = "Your response has been recorded. The work order will be prioritized and a tech will be assigned shortly. Thanks! " + "\n\n",
        ss = SpreadsheetApp.getActiveSheet(),
        cols = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0];

      // Iterate through the Form Fields
      for (var keys in cols) {

        key = cols[keys];
        entry = e.namedValues[key] ? e.namedValues[key].toString() : "";

        // Only include form fields that are not blank
        if ((entry !== "") && (entry.replace(/,/g, "") !== ""))
         var subject = (" Maintenance Work Order Request For ") + eDept;  message += key + ' :: ' + entry + "\n\n";
      }

      MailApp.sendEmail(toWhom, subject, message);
    }
  } catch (error) {
    Logger.log(error.toString());
  }
}

//********************************************************************************
//********************************************************************************
//********************************************************************************
function Email() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet1= ss.getSheets()[0];   //sheet1 (where the form data goes)
  var sheet2 = ss.getSheets()[1];  //email data
//    var sheet3 = ss.getSheets()[2];  //email data
//    var sheet4 = ss.getSheets()[3];  //warning levels
//    var sheet5 = ss.getSheets()[4];  //summary requests
//    var sheet6 = ss.getSheets()[5];  //work areas
//    var lastRow = sheet1.getLastRow();

  var currDept = "Traffic Dept";

  // *** Create the email recipient list
  var rcptvals = sheet2.getRange(2, 1, 101, 1).getValues();
  var toWhom = "";
  for (var i = 0; i < 100; ++i) {  //This is the number of rows to include on the email
    toWhom = toWhom + rcptvals[i][0] + ",";
  }

  //**********************************************************************************************************
  //*** Based on the dept, determine who else needs to be included in the email and create the email list. ***
  //**********************************************************************************************************
  // The maximum number of groups is capped at 99.
  var emailGroup = "";
  var groupToEmailRange = sheet2.getRange("C1:D100"); //max number of groups is 99
  var groupToEmail = groupToEmailRange.getValues();

  // check to see who to add to the email list based on the department
  for (var groupNum = 1; groupNum <= 99; ++groupNum) {
    if (groupToEmail[groupNum][0] == currDept) {            //find the matching department
      emailGroup = groupToEmail[groupNum][1];               //get the dept mgmt group email addresses from col 2 of the dept info
    }
  }  
  // Include additional people in the email based on the department in the email list
  //toWhom = toWhom + "," + submitter + "," + emailGroup;   
  toWhom = toWhom + "," + emailGroup;   

  //toWhom = "example@gmail.com";

  Logger.log(toWhom);
}
...