-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.gs
61 lines (51 loc) · 2 KB
/
Main.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
// Unique Google IDs to access both the Food4Philly Directory and the Membership form
const DIRECTORY_SHEET_ID = "";
const MEMBERSHIP_FORM_ID = "";
// Unique ranges to access specific data on the Directory spreadsheet
const DIRECTORY_CHAPTERS_RANGE = "Chapters!A2:A1000";
const DIRECTORY_TEAMS_RANGE = "Teams!A2:A1000";
const DIRECTORY_GRADES_RANGE = "Grades!A2:A1000";
const DIRECTORY_MEMBERS_RANGE = "Members!A2:A1000";
// Column indices for chapter, team, and grade
const CHAPTER_COLUMN = 3;
const TEAM_COLUMN = 6;
const GRADE_COLUMN = 7;
// Hex code to color cell with any missing data
const MISSING_DATA_COLOR = "#f4cccc";
/**
* Registers a Google Apps Script trigger for the program
* The function 'handleFormSubmission' (located in Triggers.gs) will be run when a new response is submitted
*/
function registerTriggers() {
const membershipForm = FormApp.openById(MEMBERSHIP_FORM_ID);
ScriptApp.newTrigger('handleFormSubmission')
.forForm(membershipForm)
.onFormSubmit()
.create();
}
/**
* Updates the Food4Philly directory with all new responses to the Membership Form
* Should be run once to batch update with all new entries
*/
function updateFullDirectory(){
const directory = SpreadsheetApp.openById(DIRECTORY_SHEET_ID);
const membershipForm = FormApp.openById(MEMBERSHIP_FORM_ID);
const responses = getFormResponses(membershipForm);
const memberSheet = directory.getSheetByName("Members");
const members = getOneDimensionalSpreadsheetData(directory, DIRECTORY_MEMBERS_RANGE);
const chapters = getOneDimensionalSpreadsheetData(directory, DIRECTORY_CHAPTERS_RANGE);
const chapterDropdown = createDropdown(DIRECTORY_CHAPTERS_RANGE, directory);
const teamDropdown = createDropdown(DIRECTORY_TEAMS_RANGE, directory);
const gradeDropdown = createDropdown(DIRECTORY_GRADES_RANGE, directory);
for (response of responses){
handleResponse(
response,
memberSheet,
members,
chapters,
chapterDropdown,
teamDropdown,
gradeDropdown
);
}
}