This is my first time posting here and I'm a newbie when it comes to understanding code. I'll try my best to clarify what is the desired result and where I am at.
I have a "column A" which is a dropdown which contains Options "1,2,3,4,5". In the same sheet I have another column - "column B" which is a dropdown which contains options "A, B"
Desired Outcome - Whenever the user selects option "2" and option "B", an email should get triggered to a recipient.
Current State - I've browsed through this thread and Cooper's solution got me to a certain extent. However, I'm not able to send the email when there are two conditions to be met. This is how I've set the trigger - The function sendNotification --> From spreadsheet --> On Edit
Any help will be much appreciated. Thanks in advance!
EDIT - This is the code I'm using -
function sendNotification(e){
if(e.range.getColumn()==9 && e.value=='Approved'){
var recipients = "blah@blah.com";
var subject = "Custom Subject Line";
var valColB=e.range.getSheet().getRange(e.range.getRow(),2).getValue();
var body = "Custom body with variable - " + valColB + "from the sheet titled - " + e.range.getSheet().getName();
MailApp.sendEmail(recipients, subject, body)
}
}
EDIT 2 - This was an alternate method I tried, but somehow even this did not work. It wouldn't work the moment I put in the IF statement inside funTwo.
function funOne(e) {
if(e.range.getColumn() == 5 && e.value == 'Option 2') {
funTwo();
}
}
function funTwo(a) {
if(a.range.getColumn() == 9 && a.value == 'Option B') {
MailApp.sendEmail('blah@blah.com, 'subject', 'body')
}
}
Add a another condition with offset
:
Try changing from
if(e.range.getColumn()==9 && e.value=='Approved'){
To
if(e.range.getColumn()==9 && e.value=='Approved' && e.range.offset(0,-1).getValue() == '2' ){ //if ninth column is edited to Approved and the corresponding eighth column is 2, then...
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.