OnEdit need to send emails from a column

送分小仙女□ 提交于 2021-02-11 15:58:08

问题


When in column O cell is mentioned "Shipped" I want to send emails in column C (with corresponding row)

Need support to get this script right

function sendEmail(e) {
    var thisSheet = e.source.getActiveSheet();
    if (thisSheet.getName() !== 'CRM' || e.range.columnStart !== 15 || e.range.rowStart == 1 || e.value !== 'Shipped') return;
    var body, headers = thisSheet.getRange(1, 1, 1, 6)
        .getValues()[0],
        thisRow = thisSheet.getRange(e.range.rowStart, 1, 1, 6)
        .getValues()[0],
        recipientsEMail = (thisSheet.getRange.columnStart !==3 || e.range.rowStart ==1)
        .getValues()[0],
        recipients = recipientsEMail,
        subject = "Your Vehicle is shipped " + e.source.getName(),
        body = "",
        i = 0;
    while (i < 6) {
        body += headers[i] +' - ' + thisRow[i] +'\n';
        i++;
    }

    MailApp.sendEmail(recipients, subject, body);
}

My sheet


回答1:


See if this works:

function sendEmail(e) {
var thisSheet = e.source.getActiveSheet();
if (thisSheet.getName() !== 'CRM' || e.range.columnStart !== 15 || e.range.rowStart == 1 || e.value !== 'Shipped') return;
var body, headers = thisSheet.getRange(1, 1, 1, 15)
    .getValues()[0],
    thisRow = thisSheet.getRange(e.range.rowStart, 1, 1, 15)
    .getValues()[0];
    var recipients = thisRow[2];
    var subject = "Your Vehicle is shipped " + e.source.getName(),
    body = "Dear Customer,\n\nYour vehicle has been shipped from Japan";


MailApp.sendEmail(recipients, subject, body);
}

You didn't say how much columns you need to use to construct the body of the email but that can be easily changed if you increase the number in the while loop.



来源:https://stackoverflow.com/questions/34966547/onedit-need-to-send-emails-from-a-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!