I am using the Add-on Scan-IT to Sheets to input inventory info - I need the function I have coded to run after every scan. The problem is, when the scan is populated to the sheet it does not trigger the onEdit or onChange.
Any advice is greatly appreciated!
No trigger activates with a change made by a script or addon. As you can read on Triggers Restrictions: «Script executions and API requests do not cause triggers to run». So, it is not possible to use them in your situation.
As a workaround you can use time triggers to run your function, or just run them manually.
Related
I'll try to be as specific as possible. This questions relates to Google Apps Script, bounded to two sheets.
I have a function that runs on edit through an installable (not simple) trigger. (Installable because it needs to call e.g. GmailApp). Call it Sheet A.
On another sheet, which we'll call Sheet B, is a script which causes an edit to be made in a cell on Sheet A.
When an edit is made manually on Sheet A, the installable on-edit script runs fine.
When the edit is made via the script on Sheet B, the installable on-edit script does not run. In other words, there doesn't seem to be any event associated with edits made by a script.
I am wondering if there is any way to trigger the on-edit script on Sheet A to run when changes are being made through another, external, bounded script.
I've looked through GAS documentation and searched as best I can here, but I cannot find an answer. I've tried to use a simple trigger, but it also does not seem to "pick up" the edit event when performed by another script.
Any help would be greatly appreciated.
Triggers only run on "human" changes. You need to rethink your flow.
If you have a function funA() changing something programmatically in a cell and you need to trigger another function funB(), just call funB() directly from funA() without counting on a trigger.
onEdit is triggered only if user updates a cell, not when the cell is updated programmatically.
You should expose onEdit from sheet A (or extract the method that actually does send the emails) and publish it as API executable
Then you can call that method from sheet B, after the edit is made programmatically.
I want to run a Google App Script function every time a change is made to my Google Doc. I have found onChange and onEdit triggers which are only available for Google Spreadsheet. I am sure there must be an edit/change trigger for Google Doc as well.
Unfortunately there are no onEdit(), onChange() triggers for Google Docs.
The triggers available for Google Docs are the following:
onOpen() triggers both simple and installable;
time driven triggers;
onInstall() simple triggers.
What you can do instead is to use a time driven trigger so in this way even though the changes are not directly triggering the execution, the trigger will still run how often you want it to.
Last but not least, you can file a Feature Request on Issue Tracker where you specify the details needed.
Reference
Apps Script Trigger;
Google Issue Tracker.
I need to detect when the user changes the name of the spreadsheet (not the sheet).
Of the triggers, the timeBased and onChange are the most likely to be the solution. I would prefer not to use timeBased as the max frequency you can use is once per hour (in an addon, which is my situation) and my use case is to update the database right after the spreadsheet name is updated.
onChange is a bit confusing, there is a changeType called OTHER that may work but there is no explanation of what events this triggers on.
Is there a list of events that trigger OTHER anywhere?
Would this work for a spreadsheet name change?
Is there another solution I haven't found yet?
Since your using an add-on, your best option might be the onOpen function. It won't trigger when the name is changed, but will when the spreadsheet is open. This might be a good compromise from the time trigger.
After testing this with the onChange trigger, I've verified that it does not fire when changing the spreadsheet name.
I've created this feature request with google, hopefully they will add this event to a trigger or create a new one
Currently there is no way to capture the spreadsheet name change, you have to go about it by checking the name during onOpen, onEdit, onChange trigger events. Not ideal at all and leaves the potential for the name change to not be captured by the add on/apps script code for some time if ever.
Probably the answer to this is simple but I am having a tough time getting my head around it.
I have a spreadsheet used by many users. I want custom onEdit and onOpen functions to run only for the user who triggers then. For example - if person B opens the spreadsheet, then only his custom onOpen trigger should run, not the custom onOpen triggers for the other users. Likewise if the user edits a cell only his custom onEdit should run.
Currently how I have set it up everyone has his own triggers but they all run the same script every time there is a trigger by any user, meaning the trigger runs 4x for no reason and it's slowing down the spreadsheet, and it also wastes script time usage for the other users who are not opening or editing the sheet.
You can have separate functions for each user and have code dynamically check for current user and run the function of current user only.
See here for getting current user. Link
Assuming the functions are the same but you just aren't wanting it to run for some users, you could use PropertiesService to store a user property to identify if it should run or not. You have to make some UI method to set the property and then you would check for the property at the beginning of each of your functions. Technically the functions would run but you could return out of them if you don't want to finish the logic.
I have a Google sheet with a function that enters a timestamp in a column if the column to its left is updated. It is triggered by the simple onedit trigger, and it only processes for a small set of cells in the sheet. It has worked fine for months with many people.
Then I added a script to do some data cleanup on a separate tab of the same doc. I use an installable trigger, so that I can schedule the cleanup to run once each week.
Unfortunately, while the scheduled installable trigger cleanup routine now works, the original onedit simple trigger timestamp routine does not. To be more precise, the timestamp routine works for me, the author of the script, but it does not work for anyone else.
Any idea how to address this?
Thank you!
the timestamp routine works for me, the author of the script, but it does not work for anyone else.
Issue can be found in Stackdriver logs. Go to Script Editor>View> Executions>Clear all filters. Check the failed logs. Most possible reason is You restricted access to those people. If the "user at the keyboard" is not permitted to do something manually, He cannot do that through scripts either. Another possible reason is Anonymous edits cannot show popups/dialogs; If you added such code to your function, Your function will fail.
Possible Solution(s):
Provide the necessary permission or
Create a installable onEdit trigger, so that the function will run under your authority. In this case, if editors are able to access your editor, they may be able to execute scripts as you. Protecting all sheets with unprotected ranges may help this, but does not provide complete security. Reducing authorised access scope might also help
Another way to do this is by creating a service account and use oauth library to access the sheet.Sample here and here.