-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateGroupSurvey.js
43 lines (32 loc) · 1.33 KB
/
GenerateGroupSurvey.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function addMultipleChoice(form, questionData) {
form.addMultipleChoiceItem()
.setTitle(questionData.title)
.setChoiceValues(questionData.choices)
.setRequired(questionData.required);
}
function addTextItem(form, questionData) {
form.addTextItem()
.setTitle(questionData.title)
.setRequired(questionData.required);
}
// forceParam is a dummy parameter whose existence forces the UrlFetch to avoid caching
// still not sure this is working properly!
function gennerateGroupSurvey(forceParam) {
// Get the questions from some source in JSON format
var surveyQuestionsJSON = UrlFetchApp.fetch("https://raw.githubusercontent.com/CNERG/group-survey/master/questions.json");
var surveyQuestionsList = JSON.parse(surveyQuestionsJSON)
var numQuestions = surveyQuestionsList.length
var form
if (numQuestions > 0) {
var formTitle = "Group Survey Form";
var form = FormApp.create(formTitle)
.setTitle(formTitle);
for (var i = 0; i < numQuestions; i++) {
if (surveyQuestionsList[i].type == "multipleChoice") {
addMultipleChoice(form, surveyQuestionsList[i])
} else if (surveyQuestionsList[i].type == "text") {
addTextItem(form, surveyQuestionsList[i])
}
}
}
}