onEdit Function in Google Apps Script Doesn't Work with Automated Row Insertion

I’m having trouble with my Google Apps Script onEdit function. It works fine when I manually change data in my spreadsheet, but it doesn’t trigger when rows are added automatically through third-party integrations.

I have a Google Sheet with two tabs - one for product inventory and another for tracking orders. When new orders come in through automation, a new row gets added to the ‘Orders’ tab. I want my script to run each time this happens to update the inventory automatically.

The function triggers correctly when I edit cells manually, but stays silent when rows are inserted programmatically. Here’s my current code:

function onEdit(event) {
    var currentSheet = event.source.getActiveSheet();
    var modifiedRange = event.range;
    if (currentSheet.getName() !== 'Orders') return;
    var itemID = getOrderID();
    var quantityRequested = getOrderAmount();
    var inventoryList = getProductArray();
    var matchedItem = locateProduct(inventoryList, itemID);
    var targetRow = findRow(itemID);
    var updateStock = deductInventory(targetRow, quantityRequested);
}

I’m not sure if I’m approaching this correctly. Any help would be appreciated since I’m still learning to code.

totally get it! yeah, onEdit is like, super limited with automated stuff. defo try onChange instead. but even then, some tools might not play nice. maybe look into a timed trigger to check for new rows regularly? it’s not a flawless fix, but worth a shot!

The onEdit trigger won’t work with automated data insertion. Third-party integrations bypass the normal editing process that fires onEdit functions - that’s why your script isn’t running when rows get added automatically. I ran into this same problem with form submissions and API integrations. Fix it by setting up an installable trigger for change detection. Use ScriptApp.newTrigger() with the onChange event type to monitor sheet modifications. I also had good luck with time-based triggers that check for new entries every few minutes by comparing row counts or timestamps. It’s not instant, but it works consistently no matter how data gets into your sheet. Way more reliable than change triggers alone, especially with multiple integrations running.

Had the same problem building inventory management for our small business. The onEdit function only fires with manual edits and does not respond to automated entries from external tools. What worked for me was to implement both onChange triggers and periodic validation checks. Set up an installable onChange trigger, complemented by a time-driven trigger that executes every 5-10 minutes to catch any missed changes. Store the last processed row number in PropertiesService to ensure your function only processes new entries and avoids reprocessing them. Your function logic appears sound; the key is to establish the right trigger setup for consistent execution.