JavaScript How to get all form triggers (not just for the current script)?

I did the following:

  1. Created a Google Form (e.g. form ID = ABC)
  2. Created a Google Sheet (let's call it sheet1)

In sheet1's script editor, installed a trigger to my form with code such as the following:

var form = FormApp.openById("ABC");
ScriptApp.newTrigger("testFunctionSheet1").forForm(form).onFormSubmit().create();

When I call the following, I see my trigger was installed properly:

ScriptApp.getUserTriggers(form);

Everything is great. I can execute code whenever a Google Form is submitted.

Problem is, later on I go ahead and create a new Google Sheet (let's call it sheet2), which has similar code:

ScriptApp.newTrigger("testFunctionSheet2").forForm(form).onFormSubmit().create();

To be safe, though, I attempt to remove all the previous triggers from all my old scripts (i.e. sheet1). However, when I run:

ScriptApp.getUserTriggers(form);

... it returns one result (testFunctionSheet2) instead of returning both testFunctionSheet1 and testFunctionSheet2. Turns out it only returns triggers that are executed by the current script!

This is problematic because it may mean I accidentally have many scripts that are all executing upon a form's submission. If I never wrote down which scripts execute for which forms, I would have no idea what exactly is run from each submission. Some of those scripts may either do the same thing (which is a waste of CPU cycles at best, or will interfere with each other at worst), or they may do completely different things and potentially clash with each other.

I want a simple way to find all script triggers that will be executed on form submission. Something like if the function actually behaved as I would expect...

I.e. ScriptApp.getUserTriggers(form) should return something like:

  • sheet1: testFunctionSheet1
  • sheet2: testFunctionSheet2

This way I can easily tell which scripts will be executed upon form submission and can manually remove the old ones, to ensure nothing clashes.

Is there a way to find out which triggers will execute across all my scripts upon form submission?


Update: The documentation for getUserTriggers() clarifies that it will never return triggers for different scripts:

Gets all installable triggers owned by this user in the given form, for this script or add-on only. This method cannot be used to see the triggers attached to other scripts.

How, then, would I know all triggers associated with a given Google Form? Note: this doesn't necessarily have to be a programmatic solution. If there was a UI element in Forms that gave me this information, that would suffice too.

Answer:1

There doesn't seem to be a way to do this, but there are some workarounds that can make things a bit more organized:

  1. Instead of installing the form trigger on a Sheet, install it on the Form. If you get into this habit, you can easily tell if there are scripts installed because the first place you'd check is in the Form's script. Simply run the get all triggers command as you tried above, and it'll work.

  2. Instead of installing the form trigger on a Form, set the form to submit its responses to the Sheet, and use the onFormSubmit() method in SpreadsheetTriggerBuilder. To find out which trigger is associated with a form becomes as simple as opening the form, then going to its destination, and then looking if that script has a trigger for the form.

  3. Hide the trigger script names in some property on the Form that you don't plan on showing to the user (e.g. customClosedFormMessage). Set it to something like This script has an active trigger associated with sheet1. You can create a helper function that before installing a trigger, it ensures that that text doesn't exist there (if you want to limit to 1 trigger per form, for example).

Answer:2

I have a kendo combobox inside a kendo grid. I use MVVM binding to bind the combobox to the items in the list. The problem is, when i select an item from the combobox dropdown everything is fine, but ...

I have a kendo combobox inside a kendo grid. I use MVVM binding to bind the combobox to the items in the list. The problem is, when i select an item from the combobox dropdown everything is fine, but ...

  1. kendo combobox inside grid
  2. combobox inside kendo grid mvc

I have mapsOrder array and mapsData array of objects: let mapsOrder = [1,2,1,3]; let mapData = [ { id: 1, gates: [ { toId: 2, coords: { x: 2, y: 42 ...

I have mapsOrder array and mapsData array of objects: let mapsOrder = [1,2,1,3]; let mapData = [ { id: 1, gates: [ { toId: 2, coords: { x: 2, y: 42 ...

I am trying to submit a form and while submitting I call a function which is myOwnFun and it runs. But if I keep pressing enter for long time, form submit repeats which I don't want. Here is the ...

I am trying to submit a form and while submitting I call a function which is myOwnFun and it runs. But if I keep pressing enter for long time, form submit repeats which I don't want. Here is the ...

  1. javascript calling function only once

Maybe I am being stupid here but I cannot figure out how to respond to a Foundation 5 TopBar dropdown selection with a javascript function. I would like to select a theme for a library I use. To set ...

Maybe I am being stupid here but I cannot figure out how to respond to a Foundation 5 TopBar dropdown selection with a javascript function. I would like to select a theme for a library I use. To set ...