Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Forms Script. Sample script on form submit. Get responses.
// gentleman script for google forms
//
// gets submitted valus:
// 1. question label
// 2. question id
// 3. response value
//
// ⚠️ This is Form trigger.
// Open script editor from form interface
// Install it wia Triggers
function onFormSubmit(e) {
// form
// https://developers.google.com/apps-script/guides/triggers/events#google_forms_events
var form = e.source;
// https://developers.google.com/apps-script/reference/forms/form-response
var formResponse = e.response;
var itemResponses = formResponse.getItemResponses();
// loop item responses
// create responses map
var response = {}, responses = [], item;
for (var i = 0; i < itemResponses.length; i++) {
item = itemResponses[i].getItem();
response = {
id: item.getId(),
label: item.getTitle(),
value: itemResponses[i].getResponse()
}
responses.push(response);
}
console.log(JSON.stringify(responses, null, 4));
// [
// {
// "id": 118013843,
// "label": "division",
// "value": "sales"
// },
// {
// "id": 579943165,
// "label": "status",
// "value": [
// "effective"
// ]
// },
// {
// "id": 988968363,
// "label": "comment",
// "value": ""
// },
// {
// "id": 23068969,
// "label": "number",
// "value": "234"
// }
// ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment