1

I am using google script editor to automate a hiring chart that allows different tasks complete (ex. creation of email account) to trigger an email to the next person to complete their task (ex. adding them to payroll)

I am using the triggerOnEdit(e) function along with the var rang = e.range; to get the active row the changes took place on the sheet and defining the column for each task.

My current issue is I am trying to use an OR statement to allow an email to be sent to the same person depending on what building is defined in the building column.

function buildingEmail(e)
{
  var range2 = e.range;
  var row2 = range2.getRow();
  var building2 = SpreadsheetApp.getActiveSheet().getRange(row2,3).getValue();
  //var building = SpreadsheetApp.getActiveSheet().getRange(30,3).getValue();
  
    
  if(building2 == ('building 1'||'building 2'))
  {
  //SpreadsheetApp.getUi().alert("Email sent to building 1 Admin");
  MailApp.sendEmail(prEmail,"New Staff Onboarding","A change has been made to the Onboarding Sheet that needs your attention. Please visit link to complete your task.");
  return;
  }

I am using || because in some google searches that seemed to be how to do an OR statement but that does not seem to be working. I have tried finding how to properly do it now but cannot seem to figure this out. Any assistance on this?

If I need to upload the entire script I can but if someone knows how to add in an OR statement I think the rest of it is working properly.

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • Does this answer your question? [Check variable equality against a list of values](https://stackoverflow.com/questions/4728144/check-variable-equality-against-a-list-of-values) – VLAZ Jun 26 '20 at 04:16

2 Answers2

2

Cooper's answer, at least at the moment I am posting this, is almost correct. There is just an extra parenthesis at the end. A somewhat cleaner version might be:

if(building2 == 'building 1' || building2 == 'building 2'){
  // Do stuff when either condition is true.
}

But beyond the unnecessary parenthesis it is really just a mater of personal preference.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
0

Try this:

if(building2=='building 1'|| building2=='building 2'))
Cooper
  • 59,616
  • 6
  • 23
  • 54