Object reference
Item response
An ItemResponse pairs one Google Form question with the answer submitted for it. Reach item responses from formResponse.getItemResponses(), then call getItem().getTitle() and getResponse().
FormApp.ItemResponseStart here
Get this object first
Call getItemResponses() on a FormResponse from event.response in a form-submit trigger, or on the latest submission from form.getResponses() in a form-bound script.
function logFirstItemTitleFromLatestResponse() {
const form = FormApp.getActiveForm();
if (!form) throw new Error('Run this from a script bound to a Google Form.');
const responses = form.getResponses();
if (!responses.length) return;
const itemResponses = responses[responses.length - 1].getItemResponses();
if (!itemResponses.length) return;
Logger.log(itemResponses[0].getItem().getTitle());
} Then use it
Common actions
Choose an action, then open its example only when you need the code.
Read the answer for a question by title
Finds the ItemResponse whose question title is Status and logs whether it has an answer.
FormApp.ItemResponseFormApp.FormResponseShow example code
/** @param {Events.FormsOnFormSubmit} event */
function checkStatusQuestionAnswered(event) {
const match = event.response.getItemResponses().find((itemResponse) => {
return itemResponse.getItem().getTitle() === 'Status';
});
const answered = Boolean(match && String(match.getResponse()).trim());
Logger.log(answered ? 'Status was answered' : 'Status was left blank');
} Log question titles and item types in a submission
Logs getItem().getTitle() and getItem().getType() for each submitted ItemResponse. The answers themselves are not logged.
FormApp.ItemResponseFormApp.ItemShow example code
/** @param {Events.FormsOnFormSubmit} event */
function logSubmittedItemTypes(event) {
const summary = event.response.getItemResponses().map((itemResponse) => {
const item = itemResponse.getItem();
return item.getTitle() + ' (' + item.getType() + ')';
});
Logger.log(summary.join(', ') || 'No item responses');
} Normalize checkbox or text answers to a string
Checkbox questions return a string[] from getResponse(), while text questions return a string. Array.isArray() handles both shapes.
FormApp.ItemResponseShow example code
/** @param {Events.FormsOnFormSubmit} event */
function countSelectedChoicesOnFirstItem(event) {
const itemResponses = event.response.getItemResponses();
if (!itemResponses.length) return;
const raw = itemResponses[0].getResponse();
const values = Array.isArray(raw) ? raw : [String(raw)];
Logger.log('Values on first item: ' + values.filter(Boolean).length);
} Technical reference
Exact names and signatures
Open method details when you need them.
At a glance
- Service
- FormApp
- Reference symbol
FormApp.ItemResponse- Object
ItemResponse- Runtime
- From signature data
Methods and signatures
Browse 6 methods
getFeedback
- getFeedback(): unknown
getItem
- getItem(): FormApp.Item
getResponse
- getResponse(): string | string[] | string[][]
getScore
- getScore(): number | null
setFeedback
- setFeedback(feedback: unknown): FormApp.ItemResponse
setScore
- setScore(score: unknown): FormApp.ItemResponse
Need the whole workflow?
Return to a task guide
Task guides cover setup, permissions, expected results, and troubleshooting as well as object methods.
Browse Google Forms tasks