mySurvey
這是一支Google Apps Script程式,讓您輕鬆提供每一用戶客製化選項進行登記、選擇或加退選的萬用系統。
AI Summary
mySurvey
A GAS library that quickly creates/updates Google Forms from spreadsheet or JSON definitions and automatically collects & manages responses.
Target Users
Intermediate GAS developers who need to automate Google Form creation for internal surveys or customer-satisfaction questionnaires.
Problems Solved
Manually building and updating Google Forms is time-consuming and error-prone.
Tags
Main Features
Generate Forms from simple JSON
Create or update a Google Form with one command by describing questions and choices in JSON or a spreadsheet.
Auto-link response collection
Automatically writes form responses to a specified spreadsheet, ready for real-time analysis.
Reusable & version-controlled surveys
Update an existing survey simply by rerunning the same definition file, making iterative surveys effortless.
Usage Examples
【Intro】Create a form with the bare minimum
// Call the library
const form = MySurvey.create({
title: 'Quick Survey', // Form title
items: [ // Question definitions
{type: 'TEXT', title: 'Name'},
{type: 'MULTIPLE', title: 'Satisfaction', choices: ['High','Normal','Low']}
]
});
Logger.log(form.getEditUrl()); // Logs edit URL
Runs instantly and gives you a two-question Google Form together with its edit URL.
【Basic】Build from JSON with response sheet linkage
// Load JSON stored in Drive
const json = DriveApp.getFileById('JSON_FILE_ID').getBlob().getDataAsString();
const survey = MySurvey.build(JSON.parse(json), {
sheetId: 'SPREADSHEET_ID' // Where responses will go
});
Logger.log(`Published URL: ${survey.getPublishedUrl()}`);
Creates a fully-fledged survey (multiple pages, required fields etc.) driven by a JSON file and links responses to the specified spreadsheet.
【Pro】Spreadsheet-driven update & response analytics
function deploySurvey() {
// 1. Read question list from spreadsheet
const ss = SpreadsheetApp.openById('DEFINITION_SHEET_ID');
const definition = MySurvey.sheetToDefinition(ss.getSheetByName('Questions'));
// 2. Update existing form or create new one
const form = MySurvey.upsert(definition, {
formId: PropertiesService.getScriptProperties().getProperty('FORM_ID')
});
// 3. Save form ID on first run
PropertiesService.getScriptProperties().setProperty('FORM_ID', form.getId());
// 4. Fetch and summarise responses
const answers = MySurvey.getResponses(form);
const summary = answers.reduce((m, a) => {
m[a.Satisfaction] = (m[a.Satisfaction] || 0) + 1;
return m;
}, {});
Logger.log(summary); // { High: 12, Normal: 5, Low: 1 }
}
Edit questions in a spreadsheet, run the script to update the form, collect responses and perform quick aggregation—all in one automated flow.