-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfall2022-check-in.gs
141 lines (98 loc) · 3.63 KB
/
fall2022-check-in.gs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
function onFormSubmit(){
var form = FormApp.openById('Enter FORM ID here');
var ss = SpreadsheetApp.openById('Enter SPREADSHEET ID here);
var nufypSlots = ss.getRange("Settings!A11:C12").getValues();
var year1Slots = ss.getRange("Settings!A4:C6").getValues();
var continuing1Slots = ss.getRange("Settings!A2:C4").getValues();
var continuing2Slots = ss.getRange("Settings!A7:C12").getValues();
var forAllSlots = ss.getRange("Settings!A11:C28").getValues();
var extraSlotsNufyp = ss.getRange("Settings!A13:C13").getValues();
var extraSlotsYear1 = ss.getRange("Settings!A14:C14").getValues();
var extraSlotsContinuing = ss.getRange("Settings!A15:C15").getValues();
var nufypChoice = [];
var year1Choice = [];
var continuingChoice = [];
for (s in nufypSlots){
if (nufypSlots[s][0] != "" && nufypSlots[s][2] > 0){
nufypChoice.push(nufypSlots[s][0]);
}
}
for (s in year1Slots){
if (year1Slots[s][0] != "" && year1Slots[s][2] > 0){
year1Choice.push(year1Slots[s][0]);
}
}
for (s in continuing1Slots){
if (continuing1Slots[s][0] != "" && continuing1Slots[s][2] > 0){
continuingChoice.push(continuing1Slots[s][0]);
}
}
for (s in continuing2Slots){
if (continuing2Slots[s][0] != "" && continuing2Slots[s][2] > 0){
continuingChoice.push(continuing2Slots[s][0]);
}
}
/////////////////////////
for (s in forAllSlots){
if (forAllSlots[s][0] != "" && forAllSlots[s][2] > 0){
nufypChoice.push(forAllSlots[s][0]);
year1Choice.push(forAllSlots[s][0]);
continuingChoice.push(forAllSlots[s][0]);
}
}
///////////////////////
if(nufypChoice.length==0){
nufypChoice.push(extraSlotsNufyp[0][0]);
}
if(year1Choice.length==0){
year1Choice.push(extraSlotsYear1[0][0]);
}
if(continuingChoice.length==0){
continuingChoice.push(extraSlotsContinuing[0][0]);
}
/*
Logger.log("Pre-duplicates:");
Logger.log(nufypChoice);
Logger.log(year1Choice);
Logger.log(continuingChoice);*/
nufypChoice_nonDuplicates = [];
year1Choice_nonDuplicates = [];
continuingChoice_nonDuplicates =[];
// deletion of duplicates - START
nufypChoice_nonDuplicates = multiDimensionalUnique(nufypChoice);
year1Choice_nonDuplicates = multiDimensionalUnique(year1Choice);
continuingChoice_nonDuplicates = multiDimensionalUnique(continuingChoice);
nufypChoice_nonDuplicates.sort();
year1Choice_nonDuplicates.sort();
continuingChoice_nonDuplicates.sort();
// delete extra dates - START
nufypChoice_nonDuplicates.shift();
year1Choice_nonDuplicates.shift();
continuingChoice_nonDuplicates.shift();
nufypChoice_nonDuplicates.shift();
year1Choice_nonDuplicates.shift();
continuingChoice_nonDuplicates.shift();
nufypChoice_nonDuplicates.shift();
year1Choice_nonDuplicates.shift();
continuingChoice_nonDuplicates.shift();
form.getItemById(1723342419).asListItem().setChoiceValues(year1Choice_nonDuplicates);
form.getItemById(388270230).asListItem().setChoiceValues(continuingChoice_nonDuplicates);
form.getItemById(1712117637).asListItem().setChoiceValues(nufypChoice_nonDuplicates);
/*
// delete extra dates - END
Logger.log("Post-duplicates:");
Logger.log(nufypChoice_nonDuplicates);
Logger.log(year1Choice_nonDuplicates);
Logger.log(continuingChoice_nonDuplicates);*/
}
function multiDimensionalUnique(arr) {
var uniques = [];
var itemsFound = {};
for(var i = 0, l = arr.length; i < l; i++) {
var stringified = JSON.stringify(arr[i]);
if(itemsFound[stringified]) { continue; }
uniques.push(arr[i]);
itemsFound[stringified] = true;
}
return uniques;
}