2

With the new Google Sheets, responses from more than one form can be sent to the same spreadsheet. This is very convenient.

However, it appears that when using the On Form Submit trigger, there is no way to distinguish between forms. This creates a major problem.

For example, I have one form that users submit to signup for a mailing list. I have a second form that users use to submit reports. I have a script that takes the reports and sends them to the mailing list recipients according to their preferences. I need to correlate variables in the mailing list and the reports in order to send the reports according to preferences. I set up the script such that whenever a report is submitted, it is automatically sent. However, when a signup form is submitted, it is triggering the script and sending emails (using information from the signup form).

Is there a way to tell Google to only trigger the script when a specific form is submitted, not when any of the forms linked to the spreadsheet is submitted?

Thanks!

duck
  • 149
  • 1
  • 4
  • 15
  • Similiar question here, http://stackoverflow.com/questions/23164835/how-does-google-know-which-onsubmit-trigger-to-execute-when-a-form-is-submitted Unfortunately no one has provided a clear answer on this. I'd like to know this as well. I guess I will use separate spreadsheet for each form for now. – s2000coder Jun 26 '14 at 15:36

1 Answers1

2

I have found a roundabout way to distinguish between forms through onFormSubmit(). Taking the fact that while there is a many-to-one relationship between Forms to a Spreadsheet, there is a one-to-one relation between a Form and a Sheet. Also, all forms append a row in their unique sheet for the response value. That row of data (as a Range) is passed as a value in e, as e.range. To get the URL of the form that was used, e.range.getSheet().getFormUrl() can be used. If the need was just to distinguish between forms, e.range.getSheet() could be used.

With that, a switch in your onFormSubmit() function could be added as a control flow towards specific (for each form) functions.

I was having the same concern. I hope this is still relevant, and for posterity sake.

TL;DR: e.range.getSheet()

XEB
  • 128
  • 1
  • 10