Search code examples
google-apps-scriptgoogle-sheetszapiertriggers

Google Apps Script onEdit Trigger Not Firing When Zapier Adds A Row


I am experiencing an issue with my Google App Script trigger not firing appropriately. My google Spreadsheet has two sheets. One that holds inventory and the other that tracks order quantity. I have a hookup with Zapier, so when a new order is placed it adds a new row to the 'Orders' sheet. I want my main function to run whenever an order is placed and a new row is added to the 'Orders' sheet. Currently, it will fire if I go into the sheet and manually edit information but it will not fire when Zapier adds a row automatically.

Here is the code:

function onEdit(e) {
    var activeSheet = e.source.getActiveSheet();
    var range = e.range;
    if (activeSheet.getName() !== 'Orders') return;
    var productOrdered = orderID();
    var amountOrdered = orderQuantity();
    var productList = productArrayFunction();
    var productMatched = findMatchingProductId(productList,productOrdered);
    var rowNumber = lookup(productOrdered);
    var subtractInventory = subract(rowNumber,amountOrdered);
}

I might be going about this the wrong way but I feel like this should work as intended. I am not a coding expert so any guidance would be greatly appreciated.


Solution

  • Zapier leverages the Google Sheets API to update your google sheet. However the onEdit event requires a user to directly interact with the sheet; that means it won't detect updates made by the API.

    I assume that you are using Zapier as an intermediary between a 3rd party API/service and Google Sheets. You can probably connect to that API/service directly using Google Apps Script. This would allow you to have more control over how data flows to your sheet and how your scripts manages and/or reacts to any changes (you might even be able to eliminate your Zapier subscription).