0

I have two different forms. Each of them is connected to the same spreadsheet. I have also set up a onFormSubmit(e) trigger. Now my question is how can I distinguish between the form submissions based on the form. I have different logic for both the forms, so I need to get some identifier through which I can check which code to run?

function onFormSubmit(e) {
  // something like this
  // if submission from FormA then do foo()
  // else if submission from FormB then do bar() 
}
Ravgeet Dhillon
  • 532
  • 2
  • 6
  • 24
  • Same Spreadsheet but different sheets - can't you just use for example `SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]` and `SpreadsheetApp.getActiveSpreadsheet().getSheets()[1]` to get the sheet with each form's responses respectively? – Rafa Guillermo Oct 21 '20 at 08:22

1 Answers1

1

The e.range.getSheet() method will give you the sheet where the form response will be stored.

Use sheet.getFormUrl() to know the URL of the Google Form that is sending this response. Use FormApp.openByUrl to get a reference of the Google Form.

Amit Agarwal
  • 10,910
  • 1
  • 32
  • 43