简体   繁体   中英

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.

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).

As Dimu Designs mentioned, you can't use a simple trigger on an API interaction. Ref: https://developers.google.com/apps-script/guides/triggers/

You could, however, run your function as the next step in a multi-step function in Zapier. Ref: https://zapier.com/help/code/#how-get-started-code-zapier

So, to be clear, I'm not answering your question; I'm just suggesting a solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM