Too many time based triggers in Google Apps Script - google-apps-script

I have a published add-on on the Google Workspace Marketplace. Suddenly users have started getting the error
This add-on has created too many time-based triggers in this document
for this Google user account.
However, when I have the add-on log what triggers are installed, there are only three, and only one of them is time-based.
What I've started noticing, though, is in the master script file (the one I edit and then publish), when I look at triggers, there are a large number of triggers that are listed as being installed by "Other User." To be clear, there are no shared users on this spreadsheet or the script attached to it. Are these "Other User" triggers coming from users of the add-on?
Otherwise, I don't know what the above error would be referring to. But I also don't understand why the triggers for every user of the add-on would install in the master script.
I also went in and editing the code where the triggers are installed for each user to FIRST delete all instances of that trigger before installing it - same error.
I went a step further and made a button just to delete every single trigger - same error.

From the documentation:
Each add-on can only have one trigger of each type, per user, per document. For instance, in a given spreadsheet, a given user can only have one edit trigger, although the user could also have a form-submit trigger or a time-driven trigger in the same spreadsheet. A different user with access to the same spreadsheet could have their own separate set of triggers.
You may want to create any triggers you need in the onInstall(e) function so that they only get created once. That way, you do not need to delete and recreate the triggers every time the add-on runs.

Related

onSpecialEdit() for Google App Script on a sheet with many users executes for all, each time

This can't be right. What am I missing?
I have a Google Sheet with scripts. The scripts are using certain ui functions that require authentication and special permissions coming from an onEdit() event. Therefore, I had to create onSpecialEdit() and the custom trigger to run that function with event source of the spreadsheet and event type onEdit(). This all works fine. Script does what it should.
From what I've seen, each person who needs to have this ability and access the special edit will need their own trigger. That is created for them automatically. Triggers all work for each person.
Now, what I see is that when I do an action that triggers onEdit(), it appears to run the onSpecialEdit() 20 times...once for each person who has that trigger....I'm assuming.
This can't be right. What am I missing? Is there another way to create triggers where they are only executed by the person triggering? Is this approach wrong?
Issue:
You want to have an onEdit trigger that has access to services that require authorization.
These services should have access private of the user who has caused the trigger to run by editing the spreadsheet.
Since the services require authorization, it cannot be a simple but an installed trigger (Restrictions).
Since installed triggers act on behalf of the user who installed them, they can only access data of the user who installed them.
Therefore, each user whose data should be accessed needs to install the trigger, so multiple triggers should be installed.
A trigger runs whenever any user edits the spreadsheet, it doesn't have to be the user who installed the trigger. Because of this, all of the installed onEdit triggers will run whenever any user edits the spreadsheet.
Solution:
Use Session.getActiveUser() and Session.getEffectiveUser() to check whether the user editing the spreadsheet (getActiveUser) is the same as the one who installed the spreadsheet (getEffectiveUser). If it's not, stop the function execution. This way, only one of the multiple onEdit triggers will make the corresponding actions.
Code sample:
function onEditTrigger(e) {
const active = Session.getActiveUser().getEmail();
const effective = Session.getEffectiveUser().getEmail();
if (active === effective) {
// TRIGGER ACTIONS
}
}

How to remove "other user" installable trigger?

Is there anyway to delete "other user" installable triggers? Being lucky enough to guess which user to delete only shows their trigger as disabled but still requires you log in their gmail to delete it which is kind of concerning when you are the "owner" of the spreadsheet?
You can't delete other user's trigger. A trigger to a script is associated with a user's Google account (and the script project).
What they do with their trigger is their own business. As the owner, you can decide if a user has the privilege to edit/view your spreadsheet. If a user has been provided with edit access, He can choose to use that privilege any way he sees fit. For example, He can choose to respond to any edit made to the sheet manually or programmatically through a script at his disposal.
If you want to know who made a particular edit, you can see the edit history of each cell.
There is no way to remove other users triggers.
Triggers are associated with the Apps Script project, not to the Spreadsheet file.
Users are able to create Apps Script Projects on any spreadsheets they have Edit access to.
If you do not want users creating Apps Script Projects on your spreadsheets, give them Read-Only Access.
The spreadsheets that already have other users triggers on them can only be "purged" by removing access.
You can permanently delete a script with all of its installable triggers after making a clean copy of it.
Go to the Overview section in the new Apps Script editor.
Click the 'Make a copy' button.
A new browser tab will be created with the new script on screen, then click the 'Delete project' button in the old script.
You can now add the triggers you need manually or by code.

How to get around time trigger limitations for Add-Ons in Google App Script?

I want to develop an Add-On to Google Sheets that gets statistics from multiple APIs every 15 minutes (at least).
I use time triggers for this in my script (which I want to make into an add-on) and that is fine.
However, I read that an Add-On can only have a time trigger with a frequence of 1 hour. This would make it impossible to make the Add-On as I need more frequent data than that.
Are there any workarounds around this issue?
Would it be feasible to have a script start and then continously add and delete a time trigger in some other way, like "run in 15 minutes again"?
As it's stated in the documentation for the Add-ons triggers, you can't set it for less than an hour [1]:
Time-driven triggers cannot run more frequently than once per hour.
Also, they can't have more than one type of trigger at the same time, meaning you could only have one time-driven trigger [1]:
Each add-on can only have one trigger of each type, per user, per
document. For instance, in a given spreadsheet, a given user can only
have one edit trigger, although the user could also have a form-submit
trigger or a time-driven trigger in the same spreadsheet. A different
user with access to the same spreadsheet could have their own separate
set of triggers.
Conclusion: I don't see any workaround possible for this.
[1] https://developers.google.com/gsuite/add-ons/concepts/triggers

Google script triggers authentication

I have created trigger programmatically on the user's profile. It's working as required since couple of months.
Last week I have changed the code of trigger program and published. But still, users are getting authentication pop up.
Do I need to programmatically delete the existing trigger of all users profile and create again?
Or any other option could you suggest

Can't Locate/Delete an Installable Trigger

I installed a form submit trigger for my project using ScriptApp around the beginning of May. The trigger has worked just fine however I now wish to uninstall the trigger and am running into problems. When I try to view all my current project triggers (Resources > Current project triggers), it returns that there are no associated triggers. Also when I try to run (Resources > All your triggers) it returns that there are no triggers shown.
I'd like to believe that this is the case, that the trigger in question has been somehow deleted but I don't believe that it is. To make sure the trigger didn't run, I de-authorized the script to run from my google account settings.
My suspicions that the trigger was not deleted were confirmed when I received a "Summary of failures for Google Apps Script: Form Processing Script" which told me my script had failed 3 times because, "Authorization is required to perform that action."
These failure e-mails also contain a statement, "To configure the triggers for this script, or change your setting for receiving future failure notifications, click here." When I click on the link, there are no triggers shown...
Here's a look at the code i used to install the trigger:
function formSubmitTriggerInstall() {
var formID = '1rOikLDUAqMWCB0ktjWzFE0oB6LmOHvXuzPAqyq0XLwE';
ScriptApp.newTrigger('processForm')
.forForm(formID)
.onFormSubmit()
.create();
}
I have also tried to locate the trigger using ScriptApp but to no avail.
Does anyone have any suggestions on how I can eliminate this trigger or get the associated trigger ID?
One other note, since I installed the trigger, the google developer's website and documentation went through a major face lift and some of the page content appears to be updated as well. Not sure that would affect my triggers though.
It was confirmed that this was a big and it was fixed by the apps script team.