I have two working scripts that I need to merge into one but I’m having trouble with onEdit triggers.
The first script automatically sorts different worksheets based on specific columns. Each worksheet can be sorted by different columns which is important for my setup.
The second script transfers entire rows between sheets when a cell contains a certain value. For example, if cell B1 contains “completed”, the whole row gets moved to another sheet and then that destination sheet gets sorted.
When I try to combine both scripts like this:
function combinedFunction() {
autoSortSheet();
transferRowsByValue();
finalSortOperation();
}
Only the row transfer part works properly. The sorting function seems to be ignored no matter which order I call them in.
Both original scripts use onEdit triggers and I think that might be causing conflicts. Has anyone dealt with similar issues when combining multiple onEdit functions? What’s the best approach to make both features work together smoothly?
Yeah, multiple onEdit triggers will clash when you combine them. Use one onEdit function instead and add conditional logic to check what changed. Use e.range.getColumn() to see which column got edited, then decide whether to sort or transfer rows. Also, throw in SpreadsheetApp.flush() before sorting - it forces Sheets to finish the row moves before trying to sort.
This isn’t really a trigger conflict - it’s an execution order problem. Google Sheets doesn’t wait for one operation to finish before starting the next when you call multiple sheet operations back-to-back. So when you transfer rows, it creates temporary data inconsistencies that mess up your sorting algorithm. I fixed this by setting up a queue system where each operation waits for the previous one to complete. Use SpreadsheetApp.getActiveSheet().getDataRange().getValues() to check your data state between operations. Also, moving rows changes your sheet dimensions, so any hardcoded ranges in your sort function break. Make your sort function recalculate the target range after each row transfer instead of using fixed ranges. The onEdit trigger works fine - you’re just trying to run dependent operations too fast on changing data.
Had the exact same problem when mixing multiple onEdit functions in Apps Script. You’re probably running into issues with how Google Sheets processes multiple operations in one trigger. Here’s what fixed it for me: dump the separate functions and put everything into one onEdit function instead. Make it handle the row transfer first, then the sorting right after. The sorting has to wait until the row stuff is completely done. I also threw in a Utilities.sleep(500) between operations - sometimes the sort fires before the row transfer finishes, making it look like nothing happened. Double-check that your sort function targets the right range after moving rows. Row transfers mess with your data range, so you’ll need to recalculate the sort range on the fly instead of using fixed references. That’s what was breaking mine - the sort kept using old range references that didn’t match the actual data anymore.