I'm attempting to develop a function for a Google Sheet with multiple forms; each form has an individual sheet in the spreadsheet book, and I am using a separate function to add data to the master sheet. The code is container-bound to the sheet file.
In particular, I am attempting to use a single onFormSubmit trigger, and then identifying the form, and therefore the appropriate function and variable passes run by onFormSubmit, by the title of the first question in each form submission that doesn't include the time-stamp. The function, as currently coded, is as follows;
//Selects onFormSubmit action based on contents of form submission. Regex compliance is enforced by forms.
function onFormSubmit(e) {
Logger.log(e);
var responses = e.response.getItemResponses();
var keyResponse = responses[1].getItem().getTitle();
Logger.log(keyResponse);
if (keyResponse == "CUNY ID") {
var cunyID = responses[1].getResponse();
cunyIDQuery(cunyID);
}
else if (keyResponse == "First Name") {
var firstName = responses[1].getResponse();
var lastName = responses[2].getResponse();
var gpa = responses[3].getResponse();
infoSubmit(firstName, lastName, gpa);
}
else if (keyResponsew == "Q1") {
var q1 = responses[1].getResponse();
var q2 = responses[2].getResponse();
var q3 = responses[3].getResponse();
gradeSubmit(q1, q2, q3);
}
else {
wrongFormError();
}
}
Unfortunately, since this is container-bound, and I'm testing as an add-on, the logger functions have not been very helpful, but I do believe that, back when I was using e.namedValues instead of e.response.getItemResponses, I was able to determine that, at the very least, the form submission seems to be passed into the function correctly. If anyone might be able to figure this out, that would be great.
var sheet=e.range.getSheet();
– Cooper