function reminder() { var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet() var data = sh.getDataRange().getValues() var d = new Date().getTime(); for (var i=1;i<data.length;i++){ if (data[i][4]<=new Date(d+7*24*60*60*1000) && data[i][4]>=new Date(d+5*24*60*60*1000) && data[i][6]==''){ MailApp.sendEmail({to:data[i][3], subject: 'Reminder Process Update Required in 1 week', htmlBody: 'Hello '+data[i][2]+', the process page for <b>'+data[i][1]+'</b> is due for review in 1 week. Please review the content and contact the Process team before its due date if amendments are required.' }) sh.getRange(i+1,7).setValue('sent') } else if (data[i][4]<=new Date(d+30*24*60*60*1000) && data[i][4]>=new Date(d+28*24*60*60*1000) && data[i][5]==''){ MailApp.sendEmail({to:data[i][3], subject: 'Reminder Process Update Required in 1 month', htmlBody: 'Hello '+data[i][2]+', the process page for <b>'+data[i][1]+'</b> is due for review in review in 1 month. Please review the content and contact the Process Mapping team before its due date if amendments are required.' }) sh.getRange(i+1,6).setValue('sent') } } }Por lo tanto, actualmente está enviando un correo electrónico a "datos [i] [3]". También me gustaría agregar hasta 2 destinatarios más a los que enviaría un correo electrónico junto con lo que hay allí, pero también si estos campos se dejan en blanco, solo debería enviar el correo electrónico. al campo que se rellena.
Aquí hay un enlace a la demostración de la hoja y el script: https://docs.google.com/spreadsheets/d/1Qw8WefbVkS-AQXi1CcZ0z2CL-P0oNSZYqeT40oVF6go/edit?usp=sharing
Creo que su objetivo es el siguiente.
En este caso, ¿qué tal la siguiente modificación?
En esta modificación, los valores de las columnas "D" a "F" se utilizan como las direcciones de correo electrónico de los destinatarios. Cuando los valores de las columnas "D" a "F" no son valores, MailApp.sendEmail no se ejecuta. Y, para su nueva estructura de hoja de cálculo, se modificó el índice de cada fila en el bucle for.
function reminder() { var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var data = sh.getDataRange().getValues(); var d = new Date().getTime(); for (var i = 1; i < data.length; i++) { var recipients = data[i].slice(3, 6).filter(String).join(","); if (recipients == "") continue; if (data[i][6] <= new Date(d + 7 * 24 * 60 * 60 * 1000) && data[i][6] >= new Date(d + 5 * 24 * 60 * 60 * 1000) && data[i][7] == '') { MailApp.sendEmail({ to: recipients, subject: 'Reminder Process Update Required in 1 week', htmlBody: 'Hello ' + data[i][2] + ', the process page for <b>' + data[i][1] + '</b> is due for review in 1 week. Please review the content and contact the Process team before its due date if amendments are required.' }); sh.getRange(i + 1, 9).setValue('sent'); } else if (data[i][6] <= new Date(d + 30 * 24 * 60 * 60 * 1000) && data[i][6] >= new Date(d + 28 * 24 * 60 * 60 * 1000) && data[i][7] == '') { MailApp.sendEmail({ to: recipients, subject: 'Reminder Process Update Required in 1 month', htmlBody: 'Hello ' + data[i][2] + ', the process page for <b>' + data[i][1] + '</b> is due for review in review in 1 month. Please review the content and contact the Process Mapping team before its due date if amendments are required.' }); sh.getRange(i + 1, 8).setValue('sent'); } } }