Home > Back-end >  Range parameters only effecting row 2 and 3? Need to effect any row in the sheet
Range parameters only effecting row 2 and 3? Need to effect any row in the sheet

Time:02-22

I'm using this script to send an e-mail to the recipient in column H with the body being column C. I have a problem with it only working with rows 2 and 3 and no other rows below. I've tried tweaking things but can't seem to figure out the glitch. Help would be appreciated. I can post a sample sheet but with the problem being simply the range and not the functionality itself, I figured it's not necessary.

function emailService(e) {
  var source = e.source;
  var sheet = source.getActiveSheet();
  var range = e.range;
  var row = range.getRow();
  var column =range.getColumn();
  console.log("column::", column);

  var targetRange = sheet.getRange(row, 1, 1, 9)
  var targetValues = targetRange.getValues();
  console.log("targetRange:: ", targetValues);
  var body = targetValues[0][2];
  var recipient = targetValues[0][7];
  var checkboxValue = targetValues[0][8];
  var subject = "Detail Request Completed"

  if(column = 9 && checkboxValue == true) {
    console.log("checkbox marked true")

    GmailApp.sendEmail(recipient, subject, body);
  } else if (column = 9 && checkboxValue == false) {
    console.log("checkbox marked false")
  } else {
    console.log("hey hey")
  }
}

CodePudding user response:

Try revising your code as shown below:

if(column == 9 && checkboxValue == true) {
   console.log("checkbox marked true")

   GmailApp.sendEmail(recipient, subject, body);
} else if(column == 9 && checkboxValue == false) {
   console.log("checkbox marked false")
} else {
   console.log("hey hey")
}
  • Related