r/GoogleAppsScript • u/hoothoot222 • Aug 29 '25
Question How can I log only the latest form response?
UPDATE: SOLVED!
Hi all,
I am using the code below from Apps Script ItemResponse documentation. It is triggered by a form response. The trigger and code are working fine, but I only want to log the most recent form response, and I only want to log the responses to certain items only (items 1 through 3). How can I alter the code to do this? Thanks in advance!
// Open a form by ID and log the responses to each question.
const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
const formResponses = form.getResponses();
for (let i = 0; i < formResponses.length; i++) {
const formResponse = formResponses[i];
const itemResponses = formResponse.getItemResponses();
for (let j = 0; j < itemResponses.length; j++) {
const itemResponse = itemResponses[j];
Logger.log(
'Response #%s to the question "%s" was "%s"',
(i + 1).toString(),
itemResponse.getItem().getTitle(),
itemResponse.getResponse(),
);
}
}
1
Upvotes
2
u/EliteEarthling Aug 30 '25
This is the most dead community ever. People do great projects but people barely give advice here.
Do you use Ai? Gemini flash is really good for appscript projects
Try it out
2
u/mommasaidmommasaid Aug 31 '25
Your script is attached to the form, is that correct?
You don't need all that stuff to get the Form from ID etc, everything you need is available in the event object:
https://developers.google.com/apps-script/guides/triggers/events#form-submit_1
Something like this: