google-apps-scriptfirebase-realtime-databasegoogle-sheetsservice-accountseventsource

How to identify onChange event source/author in the google sheets via google apps script


I need to determine if the onChange event in Google sheets is triggered by a Google service account or by a person, because I want to process the changed data only if the trigger source was human-made direct editing, otherwise stop processing.

I tried to identify it with Session.getActiverUser(), but, although the change is through the service account, shows my own email address.

I can not find anything on the Internet, nor in the Google documentation.

PS: to be more clear, I did bidirectional syncing from Firebase Realtime Database to Sheets and vice versa. Therefore, to avoid redundant update cycle, I want to stop processing as soon as change/update happens on behalf of the Service Account.

Or maybe there is some other way to avoid loop problem. I will be glad of any help


Solution

  • So, basically it is a bit a hacky way, but it works.

    As @TheMaster suggested onChange event parameter e contains user node, which in case of Service Account is empty, thus could be used to distinguish change event sources.

    devtools console screenshot