WAI
Status Update
Comments
ry...@google.com <ry...@google.com> #2
You can get the information you are seeking directly from the event. The method depends on whether you are responding to the event in Sheets or in Forms.
If you have set up a onFormSubmit trigger in Sheets, you just need to use the e.namedValues object instead of e.values. e.namedValues is a map containing the form question titles and the responses. To modify the code you used:
function respondToFormSubmit(e) {
for (var i in e.namedValues) {
Logger.log("Question " + i + " = " + e.namedValues[i]);
}
}
This will tell you directly whether a question was answered and what that answer was.
If you are using an onFormSubmit event in Forms, you instead need to make use of the e.response (FormResponse) object, which has its own methods for querying question values. See:
https://developers.google.com/apps-script/reference/forms/form-response
Either way, you can always tell which questions were answered.
If you have set up a onFormSubmit trigger in Sheets, you just need to use the e.namedValues object instead of e.values. e.namedValues is a map containing the form question titles and the responses. To modify the code you used:
function respondToFormSubmit(e) {
for (var i in e.namedValues) {
Logger.log("Question " + i + " = " + e.namedValues[i]);
}
}
This will tell you directly whether a question was answered and what that answer was.
If you are using an onFormSubmit event in Forms, you instead need to make use of the e.response (FormResponse) object, which has its own methods for querying question values. See:
Either way, you can always tell which questions were answered.
db...@gmail.com <db...@gmail.com> #3
While you can get the responses from namedValues, it's no justification for changing the behavior of the values array. The documentation still says it is an... "Array with values in the same order as they appear in the spreadsheet." No mention of any change in behavior, and there appears to be no reason to have done it, thereby forcing clients to rewrite code for no net benefit.
For those who want to continue using the array, a work-around to make it behave like it used to is here:http://stackoverflow.com/a/26975968/1677912
For those who want to continue using the array, a work-around to make it behave like it used to is here:
ad...@arizonasignsplus.com <ad...@arizonasignsplus.com> #4
Issue I have is that I can get the responses on form submit, but it just skips the question if it is for example a dropdown field type. If it's a text field it gives me an empty answer. I need an answer no matter if the user chooses anything. So I try take the response array but it doesn't match up to what's in the spreadsheet if some dropdown questions are not answered. i.e. I have code behind the form and use onFormSubmit event.
Description
And our trigger runs a script
onFormSubmit(e)
{
for (var i in e.values)
{
Logger.log("id " + i + " = " + e.values[i]);
}
}
Previous behavior of this script was
id 0 = timestamp
id 1 = first
id 2 =
id 3 = 4
id 4 =
id 5 =
id 6 = last
And current behavior is (with newly created response destination for the old form):
id 0 = timestamp
id 1 = first
id 2 = 4
id 3 = last
Which is obviously is more ergonomic result, but makes it hard to identify which columns correspond to which values