Multiple onForm Submit Triggers within the same Google Sheets Query

1,776 views
Skip to first unread message

Chris Robson

unread,
Mar 9, 2022, 6:18:44 AM3/9/22
to Google Apps Script Community
Hello,

I was wondering if it is possible to have multiple onForm Submitted triggers contained within a single Google Sheet that run different functions based on which form is submitted. 

E.g. I have two seperate GForms that add responses to a single Google Sheets file. 
So, when user 1 completes Form A, Function 1 runs. Whereas when user 1 completes Form B, Function 2 runs. I don't want to have two seperate Google Sheets files where one runs Function1 on Form Submit and Function 2 runs on the other Google Sheet file when the form is submitted as I need the data collected from both forms to part of a bigger dataset that is contained within one file so other people can access and use it.

Any help would be greatly appreciated. 

I did try the following code for the 2nd GForm within the same Google Sheet, but the result causes function 1 to run, instead of function 2.

//form 2
function secFormSubmit(){
  var form = FormApp.openById('##########################');
  ScriptApp.newTrigger('test')
    .forForm(form)
    .onFormSubmit()
    .create();
}

//function 2
function test() {

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Active Leads");
  sheet.getRange("I3").setValue("2nd Form");
 
}

Regards

CBMServices Web

unread,
Mar 9, 2022, 1:15:41 PM3/9/22
to google-apps-sc...@googlegroups.com
Chris,

From a spreadsheet perspective, you can only have one trigger based on form submit. So even though you have multiple forms and multiple sheets in your spreadsheet, there will be one function that is triggered.

You can from that function determine which form triggered it and then do the appropriate action. Look into the event object to see the source of the trigger.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/2fe5ef6f-094f-492f-a1ed-f06cc5e879b2n%40googlegroups.com.

Arne Ballegeer

unread,
Mar 13, 2022, 3:06:29 AM3/13/22
to Google Apps Script Community
I think I had something like that too.
Have 1 spreadsheet with multiple forms, and when a form is filled in, a personal email must be sent automatically with the data of that form by means of a script. Have a look at the following link, it pointed me in the right direction.

grt

Arne

Op woensdag 9 maart 2022 om 19:15:41 UTC+1 schreef George:

game over

unread,
Feb 19, 2023, 4:41:34 PM2/19/23
to Google Apps Script Community
Reply all
Reply to author
Forward
0 new messages