Triggering onChange event in google script with Sheets API

2,259 views
Skip to first unread message

Юрий Кочетков

unread,
Jul 12, 2022, 11:20:35 AM7/12/22
to Google Apps Script Community
Hello!
I have an web application that uses Sheets API to add values to specific spreadsheet using 'spreadsheets.values.update' method. On the spreadsheet side I've setup onChange trigger that supposed to fire when web application adds new values (row). This chord works with some spreadsheets and doesn't works with other. So I started to figure out the reason for such behavior. I didn't able to find any official documentation, which approved that onChange should fire on Sheets API calls and I had to performe a bunch of tests to figure out the issue. Well, it turned out that onCahnge trigger works only with Chrome V8 engine.
But this is empirical knowledge and looks like this feature is undocumented. So the question is - could I rely on undocumented component? Or, maybe I just missed some guidlines? 
Thanks

Justin Rankin

unread,
Jul 12, 2022, 2:34:09 PM7/12/22
to Google Apps Script Community
The onChange and onEdit triggers will not fire off when adding values to the spreadsheet, document, or whatever you are applying the trigger to. Really hard to find the documentation that says so, but I had a similar use case to yours. Upon doing some digging myself for around 3 weeks, the onChange and onEdit triggers only work if someone is actively using the web browser to change or edit the document that you have the trigger applied to.

cbmserv...@gmail.com

unread,
Jul 12, 2022, 3:22:03 PM7/12/22
to google-apps-sc...@googlegroups.com

Justin is correct. The triggers would not function on changes done via software updates.

 

However, since this is a webapp writing to the spreadsheet, why don’t you use that trigger to do whatever functionality you want the spreadsheet to do? You already have a trigger to use, just make use of it.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/6261a8de-4f39-443a-915b-50270d06747fn%40googlegroups.com.

Onkel Morra

unread,
Feb 21, 2023, 11:35:05 AM2/21/23
to Google Apps Script Community
Is there any workarounds to this? I'm updating a spreadsheet in a Python script using gspread and have an onEdit trigger in the sheet's app scripts, but it's not firing when the Python script is making a change, it only fires when I make a change manually in the browser.

cbmserv...@gmail.com

unread,
Feb 21, 2023, 2:45:50 PM2/21/23
to google-apps-sc...@googlegroups.com

The workaround would be to use your Python script to trigger the Google Apps Script code to do something. You can create a webapp and then use Python to kick it into action.

 

From: google-apps-sc...@googlegroups.com <google-apps-sc...@googlegroups.com> On Behalf Of Onkel Morra
Sent: Tuesday, February 21, 2023 8:35 AM
To: Google Apps Script Community <google-apps-sc...@googlegroups.com>
Subject: [Apps-Script] Re: Triggering onChange event in google script with Sheets API

 

Is there any workarounds to this? I'm updating a spreadsheet in a Python script using gspread and have an onEdit trigger in the sheet's app scripts, but it's not firing when the Python script is making a change, it only fires when I make a change manually in the browser.

--

You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

Andrew Roberts

unread,
Feb 22, 2023, 1:39:02 AM2/22/23
to google-apps-sc...@googlegroups.com
You could take a look at using Drive API push notifications, but I think that may no longer be possible.

Reply all
Reply to author
Forward
0 new messages