-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy path023_IntroToAppsScript_Project4.js
More file actions
58 lines (45 loc) · 1.7 KB
/
023_IntroToAppsScript_Project4.js
File metadata and controls
58 lines (45 loc) · 1.7 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
*
* Introduction To Apps Script
* Project: Coding Questionnaire
*
*/
// Project Lesson 1: Intro
// There is no code for this lesson
// Project Lesson 2: Setup Google Form & global variables
// switch for your own Google Form ID
// get from URL (X's in following example)
// https://docs.google.com/forms/d/XXXXXXXXXXXXXXXXXXXXXXXXX/edit
const FORM_ID = 'XXXXXXXXXXXXXXXXXXXXXXXXX'; // <-- put your Form ID in here
// Project Lesson 3
// function to find the Form IDs
function findFormIDs() {
const form = FormApp.openById(FORM_ID);
const formItems = form.getItems();
formItems.forEach(item => console.log(item.getTitle() + ' ' + item.getId()));
}
/*
1:32:41 PM Notice Execution started
1:32:42 PM Info Name: 2120132702
1:32:42 PM Info Do you have prior coding experience? 267233812
1:32:42 PM Info What programming languages do you use? 1860180947
1:32:42 PM Notice Execution completed
*/
// Project Lesson 4: update the Google Form
function updateForm_v1() {
// get the language data from the Sheet
const ss = SpreadsheetApp.getActiveSpreadsheet();
const setupSheet = ss.getSheetByName('setup');
const langVals = setupSheet.getRange(2,1,setupSheet.getLastRow()-1,1).getValues();
console.log(langVals);
// [ [ 'None' ], [ 'Apps Script' ] ]
const langValsFlat = langVals.map(item => item[0]); // ['None'] => 'None'
console.log(langValsFlat);
// [ 'None', 'Apps Script' ] // flattened array
// add these languages to the form now
// get the form
const form = FormApp.openById(FORM_ID);
const langsCheckboxQuestion = form.getItemById('1860180947').asCheckboxItem();
// populate the Form checkbox question with new language data
langsCheckboxQuestion.setChoiceValues(langValsFlat);
}