0
votes

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.

2
Zapier isn't human.TheMaster
So, is there any way to run the function after Zapier creates a new row?Logan Garske
Not by onEdit(). The question should be addressed to Zapier support. Depending on how it operates, It maybe able to call a another function. Without Zapier add-on(?) source code(?), I can't say much.TheMaster

2 Answers

2
votes

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

0
votes

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.