Konomi
Konomi

Reputation: 1

Google Apps Script: Receiving the latest google form answer

I wrote some code to get the latest answer from a google form. var formResponses = form.getResponses(); var formResponse = formResponses[formResponses.length - 1];

But it does not return the latest answer sometimes when it's triggered automatically. When I execute by hands it always works perfect. I haven't found any regularity though it does not seem like just time lag. Have you received any bug reports about the method?

Thank you.

Upvotes: 0

Views: 136

Answers (2)

Alan Wells
Alan Wells

Reputation: 31300

The reason why you would not get the last response sometimes, could only be because of multiple submissions happening in very rapid succession. If that is the case, then you will have other problems as well. You can try using LockService to prevent subsequent submissions from running until the current instance has completed.

Upvotes: 0

James D
James D

Reputation: 3142

Use the e parameter of the onFormSubmit(e) trigger.

See here for more information about the e parameter.

As an example, if you want to get all the information from the submission:

function onFormSubmit(e) {
Logger.log(e);
}

If you want to get an array of just the submission values:

function onFormSubmit(e) {
 var values = e.values;
 Logger.log(values);
}

Upvotes: 1

Related Questions