简体   繁体   中英

Email data from spreadsheet if a specific value is filled

I would like to get an email when the sheet is edited but only if a specific column has a specific value. In that case I would like to get data from the whole row that was edited.

I found and tried this solution whit a trigger that sends me an email every time the sheet is edited and it works:

function onEdit2(e){
var ss = SpreadsheetApp.getActiveSheet();  
var editedCell =  ss.getRange(e.range.rowStart, e.range.columnEnd, 1, 1);      
var body = "FYI Cell: " + editedCell.getA1Notation()+ " was changed to: "+ editedCell.getValue(); 
MailApp.sendEmail("exa...@email.com", "Edit report", body); 
} 

But I don't know how to set it to work with my conditions. I thought something like:

if( e.range.columnStart == 7 && e.value == 'OK' ) ....but than what??

It seems you have your own answer... ;-)

if( e.range.columnStart == 7 && e.value == 'OK' ){MailApp.sendEmail("exa...@email.com", "Edit report", body)}; 

Use the condition to execute the 'mail' part...

I would eventually add a column to show a mail has been sent to avoid duplicates, something like in in this tutorial , or change the background color of the cell for which a mail has been sent... your choice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM