I have this piece of code checking the sender of an email against a list I have in a google sheet.
Let's say my list has two columns (name and email).
Column name, first row: "Google"
Column email, first row: "some.one@google.com".
Then I receive an email from "some.one@google.com".
My script will take that email, check to see if I have it on my list, if so, it'll get the name of the person, "Google" in this case.
If I receive an email from someone.else@google.com though, I still want it to get the name "Google", but now based on the domain.
The script works well, however if I add a second row with name = "Google 2" and email = "random.email@google.com", and I receive an email from "some.one@google.com", it will find it as it is in my list, but it'll continue on to the else if bit where it'll also find it by domain.
It'll find Google and Google 2 when searching by domain. I want it to stop once it meets the condition first time, and take Google. Right now, it continues running and takes the last result, Google 2. I though if/else statements stopped once the condition was met first time.
If it passes through the "if" and the condition is met, I'd like it to stop, instead of going on to "else if" and returning the last result it finds.
for (let j = 2; j < lastRowMySpreadsheet; j++) {
let emailInMyList = mySpreadsheet.getRange(j, 2).getValue();
/// domainInMyList gets the column with the domains ie: "whatever@google.com" would show as only "google" in this column.
let domainInMyList = mySpreadsheet.getRange(j, 3).getValue();
if (emailFromGmail === emailInMyList) {
sourceName = mySpreadsheet.getRange(j, 1).getValue();
/// do other stuff too
} else if (onlyEmailDomain === domainInMyList) {
sourceName = mySpreadsheet.getRange(j, 1).getValue();
/// do other stuff too
}
}