Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
917 views
in Technique[技术] by (71.8m points)

google apps script - GAS "On edit" trigger not running when edited from API

I was wondering if someone encountered this issue and thought of a workaround that isn't awful.

I have a trigger on Google Spreadsheets that is configured "on edit", and it works fine if the edit occurs manually (or via formula) from within the spreadsheet itself. However if I modify a cell externally from the Sheets API v4, the cell is changed but the function isn't triggered. Am I missing something, or Google simply doesn't support triggering when change comes from "outside"?

EDIT: As per @TheMaster's suggestion, I wrote:

function test_on_change(e){
  console.log("Changed");
  console.log(SpreadsheetApp.getActiveRange().getA1Notation());
}

The e object is json of the enum that is described here.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As you can read in the Trigger Restrictions:

Script executions and API requests do not cause triggers to run. For example, calling Range.setValue() to edit a cell does not cause the spreadsheet's onEdit trigger to run.

In case you want to deploy the script as a Web App as Tanaike mentioned, you might want to check the documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...