0
votes

I have the same question as the user here: Google Apps Script - specifying form for 'on form submit' trigger 2 forms tied to different tabs in a spreadsheet that I want to trigger 2 separate functions on submission of the respective form.

Following the answer given, I tried the following code but the functions did not trigger on the submission of those forms for some reason.

var form1 = FormApp.openById('FormID1');
  ScriptApp.newTrigger('OnForm1SubmitFunction')
   .forForm(form1)
   .onFormSubmit()
   .create();

OnForm1SubmitFunction() {
   blah;
}

var form2 = FormApp.openById('FormID2');
   ScriptApp.newTrigger('OnForm2SubmitFunction')
   .forForm(form2)
   .onFormSubmit()
   .create();

OnForm2SubmitFunction() {
   blah;
}

I could use the other solution given, which uses the standard formsubmit trigger event and a check on the submission fields, eg. if(e.namedValues["Untitled Question 2"]!=undefined) to determine which form was submitted. But the first solution that ties the function trigger to a specific form, and allows separate functions triggered for each form submission, seems more elegant if I could get it to work.

Any help is much appreciated, thanks!

1

1 Answers

0
votes

I managed to figure out what I did wrong and got it working! 1) The OnSubmit Functions should receive an argument e, 2) The creation of the triggers should be in an initialization function, and 3) I was using the incorrect Form ID (didn't realise the form edit and view IDs were different!)