Multiple onEdit triggers in Google Sheets not working simultaneously

Hey everyone! I’m struggling with Google Sheets scripts. I’ve got two onEdit functions, but only one works at a time. Here’s what I’m trying to do:

First function updates a date in column J or K when columns H or I are edited:

function updateDateOnEdit(event) {
  if ([7,8].includes(event.range.getColumn())) {
    event.range.offset(0, 2).setValue(new Date());
  }
}

Second function sets a date in column O when ‘ISSUED’ is entered in column N:

function setIssuedDate(event) {
  let cellValue = event.range.getValue();
  if (event.range.getColumn() == 14 && cellValue == 'ISSUED') {
    event.range.offset(0,1).setValue(new Date());
  }
}

I’m pretty new to scripting. How can I make both of these work together? Any tips would be super helpful! Thanks!

I’ve been working with Google Sheets scripts for a while now, and I can share some insights on your issue. The problem you’re facing is common when dealing with multiple onEdit triggers. The solution is to consolidate your functions into a single onEdit() function.

Here’s how I’d approach it:

function onEdit(e) {
  if ([7,8].includes(e.range.getColumn())) {
    e.range.offset(0, 2).setValue(new Date());
  }
  
  if (e.range.getColumn() === 14 && e.range.getValue() === 'ISSUED') {
    e.range.offset(0,1).setValue(new Date());
  }
}

This combined function will handle both scenarios efficiently. Remember to remove any separate trigger setups you might have created earlier. Also, using strict equality (===) for string comparison is a good practice in JavaScript.

If you’re still having issues, double-check your script’s permissions and make sure it’s properly bound to the sheet. Let me know if you need any further clarification!

I encountered a similar issue with multiple onEdit triggers in Google Sheets. The problem is likely that you’re trying to use separate functions for each trigger. Instead, you should combine these into a single onEdit function that handles both cases. Here’s how you can modify your code:

function onEdit(event) {
  // First trigger logic
  if ([7,8].includes(event.range.getColumn())) {
    event.range.offset(0, 2).setValue(new Date());
  }
  
  // Second trigger logic
  let cellValue = event.range.getValue();
  if (event.range.getColumn() == 14 && cellValue == 'ISSUED') {
    event.range.offset(0,1).setValue(new Date());
  }
}

This consolidated function will handle both edit scenarios simultaneously. Make sure to remove any separate trigger setups and just use this single onEdit function. It should resolve your issue and allow both actions to work together seamlessly.

hey sparklinggem, i had the same problem before. the trick is to combine ur functions into one onEdit(). just put both checks in there and it’ll work for both cases. no need for separate functions. give it a try and lmk if u need more help!