The following post is a caution around onFormSubmit triggers after I recently discovered a way that somebody had inadvertently managed to execute my code simultaneously over 253 times. Now unless a Google Form is submitted by 253 individuals all at the same time ... then this is baffling.
When should an onFormSubmit trigger run?
At the point when a Google Form has been completed and the 'Submit' button pressed.
How else can the trigger be activated?
Well ... it turns out when you unlink and then link back a Google Response Sheet containing the onFormSubmit trigger, it will activate it for every single Form response collected up to that point in time ...
Explanation
- You have an onFormSubmit trigger that does some stuff when somebody fills in your Google Form e.g. it creates folders/files, sends emails, etc.
- Over time responses build up naturally as the Form continues to be used.
- Now ... somebody goes into the Form or Response Sheet and unlinks the two items, so Form submissions are not then automatically sent to the Response Sheet (but remember they are still stored in the Form itself).
- Then ... somebody goes back in and links the two items together again, which creates a 'Form responses 2' tab in the Response Sheet and immediately pushes all of the responses from the Form into it.
- WARNING ... this will mass trigger the onFormSubmit code!!!!! For every single response that the Form has ever collected.
Workarounds
There are a number of ways to avoid this from happening:
- Delete the onFormSubmit trigger before any unlinking/linking is carried out. Then recreate it once you have everything set back up.
- Link the Google Form to a different Response Sheet file that does not contain any Apps Script code / triggers. Then you could manually copy the code/triggers across if still required.
- Delete all of the responses from the Form itself so there is no data to try and push into the Response Sheet when linking it back up. Caution: ensure you are not going to lose any data this way and that you have a copy of the responses somewhere else.
No comments:
Post a Comment