1
votes

I have a google spreadsheet that takes information from two different forms.

Manually triggering using the spreadsheet UI does not let you distinguish which form is specified when choosing "OnFormSubmit" in the triggers menu.

Thus, I am using the following code (for my sheet) to manage two different triggering events for two different form-submits:

function onOpen(e) {


var form = FormApp.openById('ID of Form 1');
 ScriptApp.newTrigger('onForm1Submit')
     .forForm(form)
     .onFormSubmit()
     .create();


var signup = FormApp.openById('[ID of Form 2]');
signup.setRequireLogin(true)
 ScriptApp.newTrigger('SignUpEvent')
     .forForm(signup)
     .onFormSubmit()
     .create();
}      
function SignUpEvent(e) {
\\stuff
}

function onForm1Submit(e) {
\\stuff
}

But when I do it this way, I am recieving a failure notification on form submit:

Function: UpdateLadder

Error Message: "Authorization is required to perform that action."

Trigger: "formSubmit"

First off, how am I recieving these email notifications to begin with? I didn't manually ask for email notifications of error messages. Secondly, what's the best way for me to get "authorization"?

2

2 Answers

1
votes

For the onFormSubmit() function, you can write code to match the destination sheet to a certain function. For example, I have a spreadsheet that has 2 forms that both have sheets for destination within it. In the onFormSubmit() trigger code, here is what I did:

function onFormSubmit(e) {
  Logger.log("[METHOD] onFormSubmit");
  var sheet = e.range.getSheet();
  var sheetId = sheet.getSheetId();
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var student = ss.getSheetByName("Student Requests");
  var studentId = student.getSheetId();
  var teacher = ss.getSheetByName("Teacher Requests");
  var teacherId = teacher.getSheetId();
  if (sheetId == studentId){
    sendStudentEmail(e.range);
  }
  if (sheetId == teacherId){
    sendTeacherEmail(e.range)
  } 
} 

So, in this example, a Teacher can request using a form, and if the onFormSubmit is related to the Teacher form, then send the Teacher email, etc..

0
votes

I'm reasonably certain that onFormSubmit ties one spreadsheet to one form; it doesn't know what to do with two onFormSubmit triggers.